2.x: fix scan(seed, f) to emit accumulated values asap #5090
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For performance reasons, the
scan
delayed the emission of accumulated items by one which worked well with sources that pushed new items frequently.Unfortunately, if the source stopped emitting (without completion), the very last accumulated item was stuck and no way to get it out of
scan
. I considered this type of use being rare but apparently I was wrong.The PR changes
scan
to emit accumulated items, including the initial seed, as soon as there is request for it. The operator now uses a stable-prefetch queue-drain found throughout other operators such asobserveOn
.Remark: sadly, request trickery such as capturing the first
request
call, emitting the seed and then requesting n - 1 doesn't work because if therequest()
call itself happens from another thread and the source is empty, theonNext
andonComplete
could run concurrently.Reported in #5089