You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix#2014 Discard concatMapIterable/fromIterable's remainder on Cancel
In this change, the goal is to discard elements of the Iterable that
haven't been processed yet. The challenge is to avoid attempting doing
so for _infinite_ Iterables (which would lead to infinite discarding
loops).
If the Iterable is a Collection, it should be finite.
If both an Iterator and a Spliterator can be generated for each of the
processed Iterables, then the Spliterator is used to ensure the Iterable
is SIZED. This allows us to safely assume we can iterate over the
remainder of the iterator when cancelling, in order to discard its
elements that weren't emitted.
For Streams, since both the iterator() and spliterator() methods are
terminating the Stream we only generate the Spliterator. We use it to
check SIZED and then wrap it in an Iterator adapter for iteration (which
is what BaseStream does by default).
Implementation Notes
----
We didn't fully switch to using a Spliterator to drive the internal
iteration. It doesn't work that well, since the Iterable#spliterator
default implementation isn't SIZED and its estimatedSize() method does
not behave like hasNext().
Iterator#hasNext is far better suited for looking ahead of the emitted
element to trigger onComplete immediately after the last onNext.
0 commit comments