๐Ÿ“šย Reference


๐Ÿ“œย Chapter


Promise.race()

Promise.all()


์˜ˆ์‹œ


const promise1 = Promise.resolve(3);
const promise2 = 42;
const promise3 = new Promise((resolve, reject) => {
  setTimeout(resolve, 100, 'foo1');
});
const promise4 = new Promise((resolve, reject) => {
  setTimeout(resolve, 100, 'foo2');
});

Promise.all(
  [promise1, promise2, promise3, promise4]).then((values) => {
  console.log(values);
});
//output: Array [3, 42, "foo1","foo2"]
var p1 = new Promise((resolve, reject) => {
  setTimeout(() => resolve('ํ•˜๋‚˜'), 1000);
});
var p2 = new Promise((resolve, reject) => {
  setTimeout(() => resolve('๋‘˜'), 2000);
});
var p3 = new Promise((resolve, reject) => {
  setTimeout(() => resolve('์…‹'), 3000);
});
var p4 = new Promise((resolve, reject) => {
  setTimeout(() => resolve('๋„ท'), 4000);
});
var p5 = new Promise((resolve, reject) => {
  reject(new Error('๊ฑฐ๋ถ€'));
});

// .catch ์‚ฌ์šฉ:
Promise.all([p1, p2, p3, p4, p5])
.then(values => {
  console.log(values);
})
.catch(error => {
  console.log(error.message)
});

// ์ฝ˜์†” ์ถœ๋ ฅ๊ฐ’:
// "๊ฑฐ๋ถ€"