+str #16610 adding aggregate & aggregateWeighted ops
This commit is contained in:
parent
b1351b36ed
commit
d690067fc9
9 changed files with 492 additions and 1 deletions
|
|
@ -1239,6 +1239,58 @@ final class Source[+Out, +Mat](delegate: scaladsl.Source[Out, Mat]) extends Grap
|
|||
def conflate[S](seed: function.Function[Out, S], aggregate: function.Function2[S, Out, S]): javadsl.Source[S, Mat] =
|
||||
new Source(delegate.conflate(seed.apply)(aggregate.apply))
|
||||
|
||||
/**
|
||||
* Allows a faster upstream to progress independently of a slower subscriber by aggregating elements into chunks
|
||||
* until the subscriber is ready to accept them. For example an aggregate step might store received elements in
|
||||
* an array up to the allowed max limit if the upstream publisher is faster.
|
||||
*
|
||||
* This element only rolls up elements if the upstream is faster, but if the downstream is faster it will not
|
||||
* duplicate elements.
|
||||
*
|
||||
* '''Emits when''' downstream stops backpressuring and there is an aggregated element available
|
||||
*
|
||||
* '''Backpressures when''' there are `max` aggregated elements and 1 pending element and downstream backpressures
|
||||
*
|
||||
* '''Completes when''' upstream completes and there is no aggregated/pending element waiting
|
||||
*
|
||||
* '''Cancels when''' downstream cancels
|
||||
*
|
||||
* @param max maximum number of elements to aggregate before backpressuring upstream (must be positive non-zero)
|
||||
* @param seed Provides the first state for an aggregated value using the first unconsumed element as a start
|
||||
* @param aggregate Takes the currently aggregated value and the current pending element to produce a new aggregate
|
||||
*/
|
||||
def aggregate[S](max: Long, seed: function.Function[Out, S])(aggregate: function.Function2[S, Out, S]): javadsl.Source[S, Mat] =
|
||||
new Source(delegate.aggregate(max, seed.apply)(aggregate.apply))
|
||||
|
||||
/**
|
||||
* Allows a faster upstream to progress independently of a slower subscriber by aggregating elements into chunks
|
||||
* until the subscriber is ready to accept them. For example an aggregate step might concatenate `ByteString`
|
||||
* elements up to the allowed max limit if the upstream publisher is faster.
|
||||
*
|
||||
* This element only rolls up elements if the upstream is faster, but if the downstream is faster it will not
|
||||
* duplicate elements.
|
||||
*
|
||||
* Aggregation will apply for all elements, even if a single element cost is greater than the total allowed limit.
|
||||
* In this case, previous aggregated elements will be emitted, then the "heavy" element will be emitted (after
|
||||
* being applied with the `seed` function) without aggregating further elements to it, and then the rest of the
|
||||
* incoming elemetns is aggregated.
|
||||
*
|
||||
* '''Emits when''' downstream stops backpressuring and there is an aggregated element available
|
||||
*
|
||||
* '''Backpressures when''' there are `max` aggregated elements and 1 pending element and downstream backpressures
|
||||
*
|
||||
* '''Completes when''' upstream completes and there is no aggregated/pending element waiting
|
||||
*
|
||||
* '''Cancels when''' downstream cancels
|
||||
*
|
||||
* @param max maximum number of elements to aggregate before backpressuring upstream (must be positive non-zero)
|
||||
* @param costFn a function to compute a single element weight
|
||||
* @param seed Provides the first state for an aggregated value using the first unconsumed element as a start
|
||||
* @param aggregate Takes the currently aggregated value and the current pending element to produce a new aggregate
|
||||
*/
|
||||
def aggregateWeighted[S](max: Long, costFn: function.Function[Out, Long], seed: function.Function[Out, S])(aggregate: function.Function2[S, Out, S]): javadsl.Source[S, Mat] =
|
||||
new Source(delegate.aggregateWeighted(max, costFn.apply, seed.apply)(aggregate.apply))
|
||||
|
||||
/**
|
||||
* Allows a faster downstream to progress independently of a slower publisher by extrapolating elements from an older
|
||||
* element until new element comes from the upstream. For example an expand step might repeat the last element for
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue