Add scanAsync to Akka Streams, similar to scan but taking a Future (#21553)
* Add comprehensive tests * Add documentation * Damn comma after rebase * Add documentation for foldAsync and scanAsync * Rename aggreator and aggreating to current * Remove out availability check * Revert removing out and some refactors * Formatting documentation * Use after instead of Promise in test * Use package reference to after and some refactoring
This commit is contained in:
parent
60bea26171
commit
c3abde60d5
10 changed files with 458 additions and 4 deletions
|
|
@ -1243,6 +1243,32 @@ final class Source[+Out, +Mat](delegate: scaladsl.Source[Out, Mat]) extends Grap
|
|||
def scan[T](zero: T)(f: function.Function2[T, Out, T]): javadsl.Source[T, Mat] =
|
||||
new Source(delegate.scan(zero)(f.apply))
|
||||
|
||||
/**
|
||||
* Similar to `scan` but with a asynchronous function,
|
||||
* emits its current value which starts at `zero` and then
|
||||
* applies the current and next value to the given function `f`,
|
||||
* emitting a `Future` that resolves to the next current value.
|
||||
*
|
||||
* If the function `f` throws an exception and the supervision decision is
|
||||
* [[akka.stream.Supervision.Restart]] current value starts at `zero` again
|
||||
* the stream will continue.
|
||||
*
|
||||
* If the function `f` throws an exception and the supervision decision is
|
||||
* [[akka.stream.Supervision.Resume]] current value starts at the previous
|
||||
* current value, or zero when it doesn't have one, and the stream will continue.
|
||||
*
|
||||
* '''Emits when''' the future returned by f` completes
|
||||
*
|
||||
* '''Backpressures when''' downstream backpressures
|
||||
*
|
||||
* '''Completes when''' upstream completes and the last future returned by `f` completes
|
||||
*
|
||||
* '''Cancels when''' downstream cancels
|
||||
*
|
||||
* See also [[FlowOps.scan]]
|
||||
*/
|
||||
def scanAsync[T](zero: T)(f: function.Function2[T, Out, CompletionStage[T]]): javadsl.Source[T, Mat] =
|
||||
new Source(delegate.scanAsync(zero) { (out, in) ⇒ f(out, in).toScala })
|
||||
/**
|
||||
* Similar to `scan` but only emits its result when the upstream completes,
|
||||
* after which it also completes. Applies the given function `f` towards its current and next value,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue