Flatten a Future[Graph[SourceShape[T], M]] as Source[T, Future[M]] #22359

This commit is contained in:
cchantep 2016-09-04 16:11:49 +02:00 committed by Johan Andrén
parent db0a473cd5
commit 5b542d99fa
10 changed files with 339 additions and 10 deletions

View file

@ -171,7 +171,7 @@ object Source {
new Source(scaladsl.Source.fromFuture(future))
/**
* Start a new `Source` from the given `CompletionStage`. The stream will consist of
* Starts a new `Source` from the given `CompletionStage`. The stream will consist of
* one element when the `CompletionStage` is completed with a successful value, which
* may happen before or after materializing the `Flow`.
* The stream terminates with a failure if the `CompletionStage` is completed with a failure.
@ -179,6 +179,18 @@ object Source {
def fromCompletionStage[O](future: CompletionStage[O]): javadsl.Source[O, NotUsed] =
new Source(scaladsl.Source.fromCompletionStage(future))
/**
* Streams the elements of the given future source once it successfully completes.
* If the future fails the stream is failed.
*/
def fromFutureSource[T, M](future: Future[Graph[SourceShape[T], M]]): javadsl.Source[T, Future[M]] = new Source(scaladsl.Source.fromFutureSource(future))
/**
* Streams the elements of an asynchronous source once its given `completion` stage completes.
* If the `completion` fails the stream is failed with that exception.
*/
def fromSourceCompletionStage[T, M](completion: CompletionStage[Graph[SourceShape[T], M]]): javadsl.Source[T, CompletionStage[M]] = new Source(scaladsl.Source.fromSourceCompletionStage(completion))
/**
* Elements are emitted periodically with the specified interval.
* The tick element will be delivered to downstream consumers that has requested any elements.