-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Promise.race
use case?
#55
Comments
I think the example in the API docs is pretty nice. Its probably mostly useful for building cancelable actions. |
@spion isn't this just as easy with |
@benjamingr I think not - the difference is that any will continue to wait for the successful fulfillment of one of the promises. Basically: .all - wait success of all, fail if just one .some(arr, N) - wait success of N, fail when impossible to fulfill N (because arr.length - N + 1 have failed) .any(arr) - wait for success of 1, fail when impossible to fulfill 1 (only when everyone fails) .race(arr) - wait for 1 promise to succeed, fail if just a single one fails. .settle(arr) - wait for all promises to settle (either with a value or with an error, doesnt matter) |
|
"it's in ES6 promises" is all I needed to hear. Thanks :) |
@petkaantonov you might also want to cancel on other things :D like for example fetchData().then(renderThings); vs Promise.race(fetchData(), orRouteChangedFail()).then(renderThings); to prevent further actions to happen if the route has changed in the meantime. Although I like the switch pattern better for those |
@spion I realize they're not the same but for that specific example - I think For the second example I'd probably do:
Or something like that, listening for a route change failure and generally the |
Sorry, I didn't explain it very well. In a client side framework for example, I want the UI update to fail if the router's route changes -- there is no point in updating it anymore.
Also, Promise.any(someAction(), Promise.delay(1000)).then(value => ...) will result with |
@spion I'm merely saying I'd approach the first case differently. Instead of having
Which would in turn reject the As for For the record in C# I'd probably use a |
Umm, the goal is not to cancel Let me try to word things better
|
I'd love to hear what are some use cases to the more obscure functions like
Promise.race
:)The text was updated successfully, but these errors were encountered: