4 ms·
You're right; I'm playing a bit fast and loose with the definition of "equivalent." However, I think it's what most people want when they reach for the forEach(
by nolanl 11y ago
You're right; I'm playing a bit fast and loose with the definition of "equivalent." However, I think it's what most people want when they reach for the forEach().
In that "Promise protips" gist (https://gist.github.com/nolanlawson/6ce81186421d2fa109a4 https://gist.github.com/nolanlawson/6ce81186421d2fa109a4), I have an example of something closer to what you describe: the sequentialize() function will execute one promise after the other, and fail as soon as a single one fails.
However, if you need to actually run multiple promises in parallel, but cancel them as soon as a single one fails, then you might want something more advanced than promises, like RactiveJS (https://github.com/ractivejs/ractive https://github.com/ractivejs/ractive) or RxJS (https://github.com/Reactive-Extensions/RxJS https://github.com/Reactive-Extensions/RxJS).
- robmcm 11y agoIt would also really help if you were verbose in the naming of your methods as to weather they were async or not. At first I didn't realise db.remove() was async (sorry perhaps that's my fault). Also on your timing diagrams it may be worth indicating that methods don't start executing at the exact same time due to the single thread: doSomething().then(function () { doSomethingElse(); }).then(finalHandler); doSomething |-----------------| doSomethingElse(undefined) ..................|------------------| finalHandler(undefined) ....................|------------------| It's my understanding that the finally handler can not execute before the body of doSomethingElse has run. (Although I am unsure of a pretty/clear way to add this to a diagram ;) )