1.x: observeOn now replenishes with constant rate #3795
Merged
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.
This PR makes sure
observeOn
requests replenishments in a fixed and predictable quantity of 75% of thebufferSize
, that is, if an emission counter reaches0.75 * bufferSize
, that amount is requested and the emission counter is reset to zero. This requires saving the emission count between drain runs. If the bufferSize is 1 or 2, the replenishment will trigger after every 1 or 2 items.Note that there is only one sensitive operator-builder,
AsyncOnSubscribe
, which is mostly affected by the request pattern as it facilitates user code to respond with an Observable sequence of the requested amount.In addition, since
observeOn
now supports setting the buffer size, it can act as a rebatching operator via the help ofSchedulers.immediate()
.