Skip to content

Instantly share code, notes, and snippets.

@amysimmons
Last active June 11, 2018 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amysimmons/6015a40c1b2f82066d6477e6dd87f19b to your computer and use it in GitHub Desktop.
Save amysimmons/6015a40c1b2f82066d6477e6dd87f19b to your computer and use it in GitHub Desktop.
const p1 = Promise.resolve('twenty-two');
const p2 = Promise.resolve(22);
const p3 = Promise.reject('Doh');

Promise.race([p1, p2, p3])
  .then(function fulfilled(value) {
    console.log(value);
  })
// twenty-two 

Promise.all([p1, p2, p3])
  .then(
      function fulfilled(msgs) {
         console.log(msgs);
      },
      function rejected(error) {
        console.log(error);
      }
  )
// doh

Promise.all([p1, p2])
  .then(
      function fulfilled(msgs) {
         console.log(msgs);
      },
      function rejected(error) {
        console.log(error);
      }
  )
// ["twenty-two", 22]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment