FoldAsync op for Flow #18603
This commit is contained in:
parent
9630feb6cc
commit
efc87af58a
16 changed files with 519 additions and 620 deletions
|
|
@ -531,6 +531,16 @@ final class Source[+Out, +Mat](delegate: scaladsl.Source[Out, Mat]) extends Grap
|
|||
def runFold[U](zero: U, f: function.Function2[U, Out, U], materializer: Materializer): CompletionStage[U] =
|
||||
runWith(Sink.fold(zero, f), materializer)
|
||||
|
||||
/**
|
||||
* Shortcut for running this `Source` with an asynchronous fold function.
|
||||
* The given function is invoked for every received element, giving it its previous
|
||||
* output (or the given `zero` value) and the element as input.
|
||||
* The returned [[java.util.concurrent.CompletionStage]] will be completed with value of the final
|
||||
* function evaluation when the input stream ends, or completed with `Failure`
|
||||
* if there is a failure is signaled in the stream.
|
||||
*/
|
||||
def runFoldAsync[U](zero: U, f: function.Function2[U, Out, CompletionStage[U]], materializer: Materializer): CompletionStage[U] = runWith(Sink.foldAsync(zero, f), materializer)
|
||||
|
||||
/**
|
||||
* Shortcut for running this `Source` with a reduce function.
|
||||
* The given function is invoked for every received element, giving it its previous
|
||||
|
|
@ -1201,6 +1211,25 @@ final class Source[+Out, +Mat](delegate: scaladsl.Source[Out, Mat]) extends Grap
|
|||
def fold[T](zero: T)(f: function.Function2[T, Out, T]): javadsl.Source[T, Mat] =
|
||||
new Source(delegate.fold(zero)(f.apply))
|
||||
|
||||
/**
|
||||
* Similar to `fold` but with an asynchronous function.
|
||||
* Applies the given function towards its current and next value,
|
||||
* yielding the next current value.
|
||||
*
|
||||
* If the function `f` returns a failure and the supervision decision is
|
||||
* [[akka.stream.Supervision.Restart]] current value starts at `zero` again
|
||||
* the stream will continue.
|
||||
*
|
||||
* '''Emits when''' upstream completes
|
||||
*
|
||||
* '''Backpressures when''' downstream backpressures
|
||||
*
|
||||
* '''Completes when''' upstream completes
|
||||
*
|
||||
* '''Cancels when''' downstream cancels
|
||||
*/
|
||||
def foldAsync[T](zero: T)(f: function.Function2[T, Out, CompletionStage[T]]): javadsl.Source[T, Mat] = new Source(delegate.foldAsync(zero) { (out, in) ⇒ f(out, in).toScala })
|
||||
|
||||
/**
|
||||
* Similar to `fold` but uses first element as zero element.
|
||||
* Applies the given function towards its current and next value,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue