Off the top of my head: not sure how you are getting the parameters, if
any, to getNextItem, but since xxAsync methods like Source.unfoldAsync and
mapAsync expect a future-returning function, I would use getNextItem
(rather than identity) in one of  those to give you downstream elements of
type Option[A] and then use filter or map or collect to deal with the
Option-ness.

On Mon, Sep 11, 2017 at 1:44 PM, Ori Popowski <[email protected]> wrote:

> 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.
>

-- 
>>>>>>>>>>      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