Hi,

What is the correct way to create a source from a function which returns 
Future[Option[A]], besides a custom GraphStage?

The source should emit A elements (not wrapped in Future[Option[]]).

I considered a few options, none of them worked

*First: using RestartSource*

RestartSource.withBackoff(1.second, 1.second, 0.2) { () =>
  Source(Stream.continually(getNextItem.map(_.getOrElse(throw new 
NoSuchElementException)))).mapAsync(4)(identity)
}



This method drops elements


*Second: filtering*

Source(Stream.continually(getNextItem)).mapAsync(4)(identity).collect {
  case Some(e) => a
}



This method will create too many unnecessary calls to the resource (imagine 
a database) and cause DOS.


So what is the idiomatic / preferable way?



-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to