Comments (4)
The basic propagation story is that with observables, all completion values (whether normal, throw, or return) are pushed up the call stack, instead of flowing down the stack. Throws propagate up the stack via the observer's "throw" method. If the observer doesn't have an error handler, or itself throws an error, then the exception will propagate back down the stack.
Let's take map
with argument fn
.
With iterators, map would get the next value from upstream, execute fn
on the value, and then yield the result to the caller. If an error occurred getting the value from upstream, or during execution of fn
, then that error would propagate down the stack as a thrown exception.
With observables, map would receive the next value from upstream, execute fn
on the value, and push the result to the observer. Any errors from upstream will be forwarded (pushed) to the observer. If an error occurs during execution of fn
, then we catch that error and attempt to push it to the observer. Since we don't map over the return value, the return value is simply forwarded (pushed) to the observer.
forEach
is a little different, in that it cannot be chained any further and errors are propagated with a promise. We (I think) decided in the other thread that it should return Promise<void>
instead of Promise<R>
, with R being the type of the result value. The intention there is to provide a combinator that allows easy integration with promises in general and await
specifically.
Does that help at all?
from proposal-observable.
A little bit. I'll try to think on it more before replying. The up-then-otherwise-down seems a bit schizophrenic, but maybe after I run through it a few times it'll make more sense.
I still don't think this justifies removing the return value from forEach, unless you also remove the exception. Although, hmm, then what would you do for reduce? I guess that would have to throw away the return value, so maybe it makes sense to say that sequence terminators throw away the return value, but any exceptions "bubble"? (The path along which they bubble seems very strange though... will think on it more.)
from proposal-observable.
ForEach is meant to approximate For...of behavior which drops return value. Trying to approximate behavior of eventual for...on, to make the refactoring path easy.
Closest example to generators as streams would be itertools on pythons. Will be interesting to examine what they did here. There are also open questions about how to handle return values in merging operations. The two options seem to be to drop the return value, or provide an aggregation function ( a la reduce) to accumulate them somehow.
from proposal-observable.
forEach
is out for now
from proposal-observable.
Related Issues (20)
- Invalid test based on Interface. HOT 1
- `obs.subscribe(next, error, complete)` should bind their callbacks to `undefined` when present HOT 5
- Why does `Observable.prototype.subscribe` report thrown errors from `observer.start(sub)` asynchronously instead of just propagating them?
- Minor spec bug WRT cleanup in `subscribe`
- `Observable.from` iteration functions incorrectly assume their observer parameter is native HOT 1
- [ALTERNATIVE] Proposal for an alternative
- Cleanup function should be passed to the SubscriptionObserver
- Simplification of Observable API HOT 69
- End a subscription if a completion token is returned HOT 1
- Even simpler API HOT 4
- Reduced API with async/await support HOT 23
- Observable should be async HOT 5
- Syntax Support HOT 4
- Alternative: Pub/Sub
- Moving to an API with AbortSignal HOT 9
- Retain core API and leave operators to user-land libraries HOT 15
- Permit unsubscribe to return a promise HOT 3
- Is there any update? HOT 34
- Support [Symbol.dispose]() for unsubscribe() HOT 1
- Unsubscribe
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from proposal-observable.