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

Can onNext may be signalled before onSubscribe returns? #555

Open
onacit opened this issue Jan 14, 2024 · 1 comment
Open

Can onNext may be signalled before onSubscribe returns? #555

onacit opened this issue Jan 14, 2024 · 1 comment

Comments

@onacit
Copy link

onacit commented Jan 14, 2024

Can the subscriber.onNext(item) be invoked before the subscriber.onSubscribe(subscription) returns, e.g. the subscriber invokes subscription.request(n) within the onSubscribe(subscription) method?

void onSubscribe(Subscription subscription) {
    subscription.request(1);
    // the publisher may start (asynchronously) publishing items to the subscriber
    // which means the onNext(item) may be invoked before this method returns
    log.debug("end-of-on-subscribe");
}

void onNext(T item) {
    log.debug("next");
}

(If logging is synchronized,)
Can next be logged before the end-of-on-subscribe?

@onacit onacit changed the title Can onNext may be signaled with onSubscribe? Can onNext may be signaled before onSubscribe returns? Jan 14, 2024
@onacit onacit changed the title Can onNext may be signaled before onSubscribe returns? Can onNext may be signalled before onSubscribe returns? Jan 14, 2024
@akarnokd
Copy link
Contributor

Yes and no.

Rule §3.2 implies it is allowed. Rule §1.3 forbids overlapping concurrent invocation between onSubscribe and onNext. Thus synchronous invocation should be allowed in theory.

In practice, you may have to defer request calls happening while onSubscribe is running and reissue them after. Especially if you are mixing implementations from different vendors or your own.

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

No branches or pull requests

2 participants