Skip to content
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

Javadoc: Explain explicitly that the Emitter methods should be called non-concurrently with generate #6299

Closed
akarnokd opened this issue Nov 9, 2018 · 3 comments

Comments

@akarnokd
Copy link
Member

akarnokd commented Nov 9, 2018

The Javadocs of the generate methods as well the Emitter interface should explicitly mention that the methods should be called non-concurrently. Generate can be found in both Flowable and Observable.

generate:

<p>
Note that the {@link Emitter#onNext}, {@link Emitter#onError} and 
{@link Emitter#onComplete} methods provided to the function should be called synchronously,
never concurrently and only while the method is executing. Calling them from multiple threads 
or outside the function call is not supported and leads to an undefined behavior.

Emitter:

<p>
Note that the {@link Emitter#onNext}, {@link Emitter#onError} and 
{@link Emitter#onComplete} methods provided to the function should be called synchronously,
never concurrently. Calling them from multiple threads is not supported and leads to an 
undefined behavior.
@davidmoten
Copy link
Collaborator

I believe calling from multiple threads is supported if there is a happens-before relationship between calls. Perhaps this:

<p>
Note that there must be a <i>happens-before</i> relationship between calls to the {@link Emitter#onNext}, {@link Emitter#onError} and 
{@link Emitter#onComplete} methods. Calling those methods from multiple threads without establishing that relationship is not supported and leads to undefined behavior.

@akarnokd
Copy link
Member Author

Fundamentally, the calls should not escape the callback method and one would have to block the callback if the onNext happens asynchronously to the method. Still you can only call it once and the blocking implicitly establishes this relationship.

@davidmoten
Copy link
Collaborator

Sounds good, thanks @akarnokd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants