+str #19041 deterministic interleave operation

This commit is contained in:
Alexander Golubev 2015-12-10 22:20:42 -05:00
parent fe3c34ed00
commit b9faf9d628
4 changed files with 74 additions and 17 deletions

View file

@ -698,6 +698,32 @@ class SubFlow[-In, +Out, +Mat](delegate: scaladsl.SubFlow[Out, Mat, scaladsl.Flo
def merge[T >: Out](that: Graph[SourceShape[T], _]): SubFlow[In, T, Mat] =
new SubFlow(delegate.merge(that))
/**
* Interleave is a deterministic merge of the given [[Source]] with elements of this [[Flow]].
* It first emits `segmentSize` number of elements from this flow to downstream, then - same amount for `that`
* source, then repeat process.
*
* Example:
* {{{
* Source(List(1, 2, 3)).interleave(List(4, 5, 6, 7), 2) // 1, 2, 4, 5, 3, 6, 7
* }}}
*
* After one of upstreams is complete than all the rest elements will be emitted from the second one
*
* If it gets error from one of upstreams - stream completes with failure.
*
* '''Emits when''' element is available from the currently consumed upstream
*
* '''Backpressures when''' downstream backpressures. Signal to current
* upstream, switch to next upstream when received `segmentSize` elements
*
* '''Completes when''' the [[Flow]] and given [[Source]] completes
*
* '''Cancels when''' downstream cancels
*/
def interleave[T >: Out](that: Graph[SourceShape[T], _], segmentSize: Int): SubFlow[In, T, Mat] =
new SubFlow(delegate.interleave(that, segmentSize))
/**
* Combine the elements of current [[Flow]] and the given [[Source]] into a stream of tuples.
*