Closed yelouafi closed 6 years ago
https://github.com/paldepind/flyd-switchlatest is what you want probably
Yes, that's the way to do in other libs like bacon.js. If it's this is the desired behavior it' be preferable to mention it in the docs.
I'm not particularly happy with this behavior.
The tricky thing is that sometimes order matters and in some cases it don't. And when it doesn't matter you don't want slow promises to block results from later promises.
IMO the default behavior should be preserving the order. The other case can be handled by something like
stream$.flatmap( v => flyd.fromPromise( $.ajax(...) )
I agree.
I believe the default behavior should do /the least special thing/. That's because the "I expect responses to preserve ordering" problem can be solved in at least two different ways:
I don't think there actually exists a single "intuitive" approach to this async problem, and it largely depends on what you're solving. The current default behavior is "dumb" and adds no special logic, leaving that as a problem to be solved with more specialized stream utilities.
You should not turn your brain off during async handling or trust in a default behavior. Always assume that things both come out of order and are dropped from responding at all.
If the promises are resolved in an arbitrary order (eg. the second promise resolve before the first) then the stream wll be updated with an outdated value