-
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
TCP, for...on, and Synchronous Subscription #65
Comments
One option is a Another option is to pass the subscription as a second argument to the |
That would seem to be a natural fit for this use case, since you are essentially wanting to cancel from within the |
@zenparsing honestly, thinking about this and talking to @jhusain who was standing over my shoulder two seconds ago, the Basically, myObservable.subscribe({
start(subscription) {
},
next(value) {
},
}); |
... in fact, RxJS 5 was heavily leaning toward implementing the |
But that's not necessary for the use case presented here. Besides, that seems kinda weird. In what case would you want to synchronously unsubscribe before any data was delivered? Wouldn't you just not call An advantage of providing a second parameter to |
It's not that much weirder than using Observable to deal with synchronous resources to begin with. Suppose an Observable is going to animate some element and report the element's current position. If the first step of the animation occurs synchronously, then by the time |
Mixing synchronous and asynchronous is the recipe for disaster. |
To be honest, I always thought of observables as something used strictly for Async code. But that might be because of the way I use them in my applications. |
As of be763e3, added support for an optional |
@jhusain Since we now support the |
One of the promises of Observable is that it can allow us to get TCP for push streams via a future theoretical for...on syntax. Here's an example of for...on in action:
Although in the example above the Observable returned by getPrices() would certainly be asynchronous, Observables may be synchronous. If an Observable is synchronous then it is not possible to unsubscribe before receiving data, because the Subscription object is not returned until the subscribe method completes:
Given this constraint there will be no way to support the
break
keyword in afor
...on
loop. As a consequence we lose TCP. Note the following example:In the example above, if syncObservable synchronously notified the numbers 4, 5, and 6 and then completed, we would see the following console output...
...instead of this nothing at all.
Unfortunately an inability to synchronously unsubscribe would appear to be a death blow for TCP. If Observables are to be synchronous as we've concluded, we need to support sync unsubscription to enable TCP in the future.
The text was updated successfully, but these errors were encountered: