Drew Kutcharian
unread,Dec 30, 2016, 5:29:55 PM12/30/16Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Akka User List
Hi,
I have a use case where I poll a datasource for items and as long as there are items present I process them as quickly as possible, but when there are no items, I would like to poll every X seconds. Is there a built-in construct in Akka Streams that I can use?
I'm currently using `Source.unfoldAsync` to get the records from the data source. One "bad" option is to just call `Thread.sleep(XXX)` inside `Source.unfoldAsync` when the datasource returns no results (as demonstrated below), but I want to see if there's a better option.
Source.unfoldAsync[NotUsed, Seq[Item]](NotUsed) { _ =>
service.getItems flatMap { items =>
if (items.isEmpty) {
//TODO Fix this!!!
Thread.sleep(30 * 1000) //30 seconds
}
Future.successful(Some((NotUsed, items)))
}
}
I can probably improve on the `Thread.sleep(XXX)` by using having some "State" object and have smaller waits, but I feel like that's not going to be that much better.
Any input is appreciated.
Thanks,
Drew