1.x: observeOn now replenishes with constant rate#3795
Merged
akarnokd merged 1 commit intoReactiveX:1.xfrom Apr 8, 2016
Merged
1.x: observeOn now replenishes with constant rate#3795akarnokd merged 1 commit intoReactiveX:1.xfrom
akarnokd merged 1 commit intoReactiveX:1.xfrom
Conversation
This was referenced Mar 31, 2016
9a8daca to
23862c1
Compare
Contributor
|
👍 |
| this.on = NotificationLite.instance(); | ||
| this.bufferSize = (bufferSize > 0) ? bufferSize : RxRingBuffer.SIZE; | ||
| int calculatedSize = (bufferSize > 0) ? bufferSize : RxRingBuffer.SIZE; | ||
| this.limit = calculatedSize - (calculatedSize >> 2); |
Member
There was a problem hiding this comment.
What do you think about a less efficient (but more readable): (int) (calculatedSize * 0.75) ?
Member
|
Other than the previous comment, 👍 |
23862c1 to
e2331e3
Compare
Member
Author
|
That formula doesn't work if calculatedSize == 1. I've updated the PR with a comment on the calculation. |
Member
|
👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
observeOnrequests 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
observeOnnow supports setting the buffer size, it can act as a rebatching operator via the help ofSchedulers.immediate().