-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Make defer() wait until request > 0 before calling Func0 #3816
Comments
Defer has nothing to do with backpressure because it just routes the subscriber to a generated Observable. Deferring the creation of the actual Observable until the first non-zero request requires completely different internals. Besides, there are standard, stable API tools for your case: defer(() -> just("whatever").map(v -> b.get())); |
I'm not saying it can't be done with the stable APIs, just that it's a bit more convoluted than should be necessary.
But would you write that same behavior if implementing defer today? Or would you have it wait until |
I've written In addition, if |
So does that mean you'd support this change to I'm perfectly happy if the answer is "we can't change this" and the focus should be on In general I'm 👎 on a new operator since it would have to go through stabalization behind both |
I don't support changing defer and perhaps fromCallable should be fast tracked to stable version. |
Sounds good 👍 |
Currently the
defer
operator calls its suppliedFunc0
immediately upon subscription as documented. Because this operator is usually used to delay work of some kind, this can prematurely trigger that work before the downstream consumer actually requests a non-zero amount.A failing test, to illustrate:
In this test, the "work" (aka
b.get()
) ran before the downstream consumer actually wanted a value produced. If you think ofb.get()
as, say, an HTTP request or something based on time, etc. the problem becomes more clear.I haven't looked, but I would guess that
defer
's behavior was implemented prior to the backpressure concept being introduced.I'll leave it up to the library maintainers to determine the risk of changing the behavior, but I want to again note one thing which started this conversation (from comments in #3780): there currently doesn't exist an easy, sane, stable API for deferring work that is backpressure aware as described above. So if it's determined to be too risky to alter
defer
, fast-trackingfromCallable
to stable and things likeSyncOnSubscribe
would be useful. This is of great concern to library developers, not so much application developers, where only stable APIs can safely be used.The text was updated successfully, but these errors were encountered: