Lazy source (#21081)

This commit is contained in:
Johan "Party Cannon" Andrén 2016-11-25 16:25:26 +01:00 committed by Patrik Nordwall
parent 0d4858c627
commit 267f31149c
7 changed files with 218 additions and 1 deletions

View file

@ -221,6 +221,14 @@ object Source {
def failed[T](cause: Throwable): Source[T, NotUsed] =
new Source(scaladsl.Source.failed(cause))
/**
* Creates a `Source` that is not materialized until there is downstream demand, when the source gets materialized
* the materialized future is completed with its value, if downstream cancels or fails without any demand the
* `create` factory is never called and the materialized `CompletionStage` is failed.
*/
def lazily[T, M](create: function.Creator[Source[T, M]]): Source[T, CompletionStage[M]] =
scaladsl.Source.lazily[T, M](() => create.create().asScala).mapMaterializedValue(_.toJava).asJava
/**
* Creates a `Source` that is materialized as a [[org.reactivestreams.Subscriber]]
*/