Akka: Factory version of Source `fromFutureSource`

Created on 3 Jan 2019  Â·  3Comments  Â·  Source: akka/akka

When using Source.fromFutureSource a single Future is re-used for every materialisation. A common usecase for this is doing an async action to initialise a Source e.g. hitting a database to get some initial state. A version that takes a () => Future[Source] would be more useful in these cases that would behave more like a Task than a Future

1 - triaged

Most helpful comment

Another alternative would be lazily(() => Source.fromFutureSource(...))

All 3 comments

fromSourceCompletionStage too

lazilyAsync has such a type signature:

def lazilyAsync[T](create: () ⇒ Future[T]): Source[T, Future[NotUsed]]

Well almost. It would have to be combined with .flatMapConcat:

Source.lazilyAsync(() => Future.successful(Source.single(1))
  .flatMapConcat(identity)

Another alternative would be lazily(() => Source.fromFutureSource(...))

Was this page helpful?
0 / 5 - 0 ratings