Skip to main content

Command Palette

Search for a command to run...

Promise.race()

Published
1 min readView as Markdown

Returns the first resolved promise from the list.

const getAnyItem = async (itemId1, itemId2) => {
  return Promise.race([
    fetch(`https://jsonplaceholder.typicode.com/albums/${itemId1}`),
    fetch(`https://jsonplaceholder.typicode.com/albums/${itemId2}`),
  ]).then((item) => {
    // ...
  });
};
getAnyItem(2, 5);

More from this blog

Codedrops.tech

49 posts