-
Notifications
You must be signed in to change notification settings - Fork 90
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
Idea for sync subscription api #29
Comments
Nice to e-see you here! Quoting some of my comments from earlier about sync subscription:
And later:
I'm also with @zenpraing in that I'm not sure I understand your sync use case but would like to learn more about it ::) |
This would cause Zalgo, we might as well make it synchronous. Namely it is possible in this scheme to observe whether or not the a subscription happened before or after a value was received. |
You as well!
Yep, this is not as much of a performance argument as a more inclusive general use cases argument.
Well, not exactly, if it were fully synchronous you couldn't do this: var subscription = observable.subscribe(generator)
subscription.unsubscribe() And be guaranteed that the
As I understand it Zalgo matters for promises because they're an object which is passed around/chained, so the async guarantees of the promise matter far beyond the initial call site. Unlike promises, the effects of Observables are more or less limited to the containing scope(s), so it seems it'd be appropriate the consumer be able to shortcut the async guarantee as they are aware of the behavior of the observable, basically inverting the control of the guarantee of subscription execution a bit. |
That has not been my experience with observables - in libraries like RxJS (which I often use with React) observables are passed all around, chained, and moved between scopes. Being able to shortcut a guarantee - especially if the guarantee is not the obvious default doesn't sound like much of a guarantee at all. With a symbol it at least looks private :) |
Sure, probably the case for the higher order functions wrapping the observable primitive, but FWIW the RxJS Observable does not make any guarantees of asynchrony in the subscription. Also, potentially relevant: ReactiveX/rxjs#12 (comment) Anyway, yeah maybe the Symbol works as long as it's sticking around, just wanted to throw out another idea for this and see what anyone thought. |
Closing in favor of discussion on #38 |
Creating a separate ticket for discussion from #25, as the ticket was originally about the naming of
Symbol.observer
but shifted to discussion of the pros/cons of providing both sync/async subscription apis.I agree that there is confusion in presenting multiple entry points for creating a subscription, but a fully async api seems to potentially limit any observable use cases where sync may be desired / beneficial.
What if the
subscription
object returned fromsubscribe
containing two methods:unsubscribe
andconnect
The
connect
would allow for the subscription consumer to signal to the observable it is ready to receive values (synchronously or otherwise). Calls toconnect
after subscription or unsubscription have taken place would have no effect.This would maintain a unified
subscribe
api, give the consumer more control over both thesubscription
and theunsubscription
behavior (defaulting to the potentially less confusing), and ifconnect
is not called the default behavior would be as currently defined - thescheduledSubscription
would take place as it is enqueue'd normally.The text was updated successfully, but these errors were encountered: