Content: Issue with "Promise.race()": …

Created on 24 Jan 2021  Â·  3Comments  Â·  Source: mdn/content

MDN URL: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race

What information was incorrect, unhelpful, or incomplete?

The example does not display the difference with Promise.any()

Specific section or headline?

The example

What did you expect to see?

The difference with Promise.any()

I suggest to put this example for Promise.race():

`
const promise1 = new Promise((resolve, reject) => {
setTimeout(resolve, 500, 'one');
});

const promise2 = new Promise((resolve, reject) => {
setTimeout(reject, 100, 'two');
});

Promise.race([promise1, promise2]).then((value) => {
console.log('succeeded with value:', value);
}).catch((reason) => {
console.log('failed with reason:', reason);
// Only promise1 is fulfilled, but promise2 is faster
});
// expected output: "failed with reason: two"
`

And this example for Promise.any():

`
const promise1 = new Promise((resolve, reject) => {
setTimeout(resolve, 500, 'one');
});

const promise2 = new Promise((resolve, reject) => {
setTimeout(reject, 100, 'two');
});

Promise.any([promise1, promise2]).then((value) => {
console.log('succeeded with value:', value);
// Only promise1 is fulfilled, even though promise2 settled sooner
}).catch((reason) => {
console.log('failed with reason:', reason);
});
// expected output: "succeeded with value: one"
`

Did you test this? If so, how?

I tested both examples on Firefox devtools' console.



MDN Content page report details

30 minute task JS

Most helpful comment

All 3 comments

I want to take on this issue.

@keiya01 assigned! Thank you for your offer of help, and please feel free to ask if you have any questions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sideshowbarker picture sideshowbarker  Â·  3Comments

Elchi3 picture Elchi3  Â·  4Comments

arturcarvalho picture arturcarvalho  Â·  5Comments

lychyi picture lychyi  Â·  3Comments

sideshowbarker picture sideshowbarker  Â·  4Comments