FlowOperationsSplitWhen Method |
Name | Description | |
---|---|---|
SplitWhenTIn, TOut, TMat(FlowTIn, TOut, TMat, FuncTOut, Boolean) |
This operation applies the given predicate to all incoming elements and
emits them to a stream of output streams, always beginning a new one with
the current element if the given predicate returns true for it.
| |
SplitWhenTIn, TOut, TMat(FlowTIn, TOut, TMat, SubstreamCancelStrategy, FuncTOut, Boolean) |
This operation applies the given predicate to all incoming elements and
emits them to a stream of output streams, always beginning a new one with
the current element if the given predicate returns true for it. This means
that for the following series of predicate values, three substreams will
be produced with lengths 1, 2, and 3:
{{{
false, // element goes into first substream
true, false, // elements go into second substream
true, false, false // elements go into third substream
}}}
In case the * first * element of the stream matches the predicate, the first
substream emitted by splitWhen will start from that element. For example:
{{{
true, false, false // first substream starts from the split-by element
true, false // subsequent substreams operate the same way
}}}
The object returned from this method is not a normal SourceTOut, TMat or FlowTIn, TOut, TMat,
it is a SubFlowTOut, TMat, TClosed. This means that after this combinator all transformations
are applied to all encountered substreams in the same fashion. Substream mode
is exited either by closing the substream (i.e. connecting it to a SinkTIn, TMat)
or by merging the substreams back together; see the ToTMat2(IGraphSinkShapeTOut, TMat2) and
MergeSubstreams methods
on SubFlowTOut, TMat, TClosed for more information.
It is important to note that the substreams also propagate back-pressure as
any other stream, which means that blocking one substream will block the SplitWhenTIn, TOut, TMat(FlowTIn, TOut, TMat, SubstreamCancelStrategy, FuncTOut, Boolean)
operator itself—and thereby all substreams—once all internal or
explicit buffers are filled.
If the split predicate throws an exception and the supervision decision
is Stop the stream and substreams will be completed
with failure.
If the split predicate throws an exception and the supervision decision
is Resume or Restart
the element is dropped and the stream and substreams continue.
Emits when an element for which the provided predicate is true, opening and emitting a new substream for subsequent element Backpressures when there is an element pending for the next substream, but the previous is not fully consumed yet, or the substream backpressuresCompletes when upstream completes Cancels when downstream cancels and substreams cancel |