Skip to content

Operators toList and toSortedList now support backpressure #2901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2015

Conversation

akarnokd
Copy link
Member

Added support for backpressure in toList and toSortedList: they emit their buffered content only when downstream actually requested it.

Few other notes:

  • Added overload to toSortedList taking a initialCapacity argument which should help reduce the number of times the buffer needs to be resized.
  • The Func2 parameter of toSortedList is now wrapped once per operator instead of once per subscriber.
  • Using non-final list buffers which are set to null on completion to not hold onto the buffer.
  • toSortedListnow returns a modifiable ArrayList: since it is a handoff procedure, there is no value in forcing a non-modification constraint on the emitted list (similar to toList even before this PR).

@davidmoten
Copy link
Collaborator

Cool. I'll be using that initialCapacity and SingleDelayedProducer will be useful too.

@@ -101,6 +107,9 @@ public void onNext(T value) {
}

};
o.add(result);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't o just be passed into the Subscriber constructor?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because if the result Subscriber receives its Producer via setProducer, the default behavior is to call setProducer on op set by the constructor and thus it can overwrite our SingleDelayedProducer.

@benjchristensen
Copy link
Member

Good changes.

benjchristensen added a commit that referenced this pull request Apr 29, 2015
Operators toList and toSortedList now support backpressure
@benjchristensen benjchristensen merged commit aeee037 into ReactiveX:1.x Apr 29, 2015
@akarnokd akarnokd deleted the ToSortedListBackpressure branch April 29, 2015 06:47
@benjchristensen benjchristensen mentioned this pull request Apr 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants