-
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
Motivate subscribe vs forEach #20
Comments
Async/Await Observation. async function getPriceHigh(stock) {
let delta,
high = Number.MIN_VALUE;
let socket = new WebSocket(“/dailyPrices/" + stock);
await Observable.from(socket).forEach(price => {
if (price > high) {
high = price;
}
});
return high;
} |
An interesting question on the table is if we could merge So in the example, you could just replace the await Observable.from(socket).subscribe(price => {
if (price > high) {
high = price;
}
}); It would be a nice simplification, all other things being equal. |
Yes, this definitely seems like a good idea to merge the two - there is nothing preventing subscribe from being a |
Not sure why this is attractive. Promise essentially duplicates semantics of return() and throw() callbacks passed to subscribe. Would also like to understand performance implications. |
what a happens if I do this: try { Gives the developer of the opportunity to duplicate error handling logic two places. furthermore the Observer callbacks may or may not be executed synchronously, whereas the promise error will only be executed asynchronously. This seems like a big foot gun to me. |
Big mistake to build observable with promises. There is too much semantic overlap, coupled with impedance mismatch. adapting between them is unambiguous. |
Yes, agreed. It seems this proposal could be greatly simplified by removing subscribe and [Symbol.observe] in favor of forEach---at least, assuming we get cancelable promises. With that assumption there's no loss in power and a great increase in interoperability and compositionality. |
I agree as well and withdraw the suggestion : ) |
Withdrawing Symbol.observe and subscribe on the assumption that Cancellable On Tue, Jun 2, 2015 at 1:35 PM, zenparsing notifications@github.com wrote:
|
Yeah, agreed. I like the plan of keeping both for now in the hope of removing one if we get cancellable promises shipping soon. Nice. I still think having both [Symbol.observe] and subscribe is a bit redundant but I haven't dug into it much and we can move that to another bug. |
Any objections to closing this one? |
Resolution sounds good to me 👍 |
Re-reading this, why would Can't subscribe return a |
@benjamingr because |
Yes, but why not both? Why can't it have |
Because at that point someone will argue that it should be a cancelable promise, which marries the two proposals. I don't think cancelable promises are a great idea, personally. |
I agree (with not marrying the proposals). What I'm asking is - why can't we return a promise which is a subscription that can be disposed? That way if in the future cancellable promises make it we'll also make the returned promise cancellable to benefit from facilities but we get a subscription with a |
@benjamingr at this point I honestly think the subscribe function should return a generator type that also has the |
The generator subscription proposal is starting to grow on me. Since it is now a sequence, I wonder if It would require |
Hey, can we get an example motivating why both subscribe and forEach are needed?
The text was updated successfully, but these errors were encountered: