+str #19041 deterministic interleave operation
This commit is contained in:
parent
15cc65ce9d
commit
737e7b8dfc
6 changed files with 332 additions and 2 deletions
|
|
@ -498,6 +498,47 @@ final class Source[+Out, +Mat](delegate: scaladsl.Source[Out, Mat]) extends Grap
|
|||
matF: function.Function2[Mat, M2, M3]): javadsl.Source[Out, M3] =
|
||||
new Source(delegate.alsoToMat(that)(combinerToScala(matF)))
|
||||
|
||||
/**
|
||||
* Interleave represents deterministic merge of the given [[Source]] with elements of this [[Source]].
|
||||
* It takes `request` number of elements from this source to emit downstream, then - same amount for given one,
|
||||
* then repeat process from the beginning.
|
||||
*
|
||||
* Example:
|
||||
* {{{
|
||||
* Source.from(Arrays.asList(1, 2, 3)).interleave(Source.from(Arrays.asList(4, 5, 6, 7), 2)
|
||||
* // 1, 2, 4, 5, 3, 6, 7
|
||||
* }}}
|
||||
*
|
||||
* After one of sources is complete than all the rest elements will be emitted from the second one
|
||||
*
|
||||
* If one of sources gets upstream error - stream completes with failure.
|
||||
*
|
||||
* '''Emits when''' element is available from current stream or from the given [[Source]] depending on what was pulled
|
||||
*
|
||||
* '''Backpressures when''' downstream backpressures
|
||||
*
|
||||
* '''Completes when''' this [[Source]] and given one completes
|
||||
*
|
||||
* '''Cancels when''' downstream cancels
|
||||
*/
|
||||
def interleave[T >: Out](that: Graph[SourceShape[T], _], result: Int): javadsl.Source[T, Mat] =
|
||||
new Source(delegate.interleave(that, result))
|
||||
|
||||
/**
|
||||
* Interleave represents deterministic merge of the given [[Source]] with elements of this [[Source]].
|
||||
* It takes `request` number of elements from this source to emit downstream, then - same amount for given source,
|
||||
* then repeat process from the beginning.
|
||||
*
|
||||
* After one of sources is complete than all the rest elements will be emitted from the second one
|
||||
*
|
||||
* If one of sources gets upstream error - stream completes with failure.
|
||||
*
|
||||
* @see [[#interleave]].
|
||||
*/
|
||||
def interleaveMat[T >: Out, M, M2](that: Graph[SourceShape[T], M], result: Int,
|
||||
matF: function.Function2[Mat, M, M2]): javadsl.Source[T, M2] =
|
||||
new Source(delegate.interleaveMat(that, result)(combinerToScala(matF)))
|
||||
|
||||
/**
|
||||
* Merge the given [[Source]] to the current one, taking elements as they arrive from input streams,
|
||||
* picking randomly when several elements ready.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue