LoginSignup
0
0

More than 3 years have passed since last update.

Promise.allに終了済みのPromiseを渡しても、エラーなく素通りする

Posted at
const sleep = msec =>
  new Promise(resolve =>
    setTimeout(() => {
      console.log(`sleep end ${msec}`);
      resolve();
    }, msec)
  );
const exec = async () => {
  console.log(`start ${new Date()}`);
  const promise1 = sleep(1000);
  await sleep(3000);
  console.log("begin promise all");
  await Promise.all([promise1]);
  console.log(`end ${new Date()}`);
};
exec();

結果

start Wed Sep 18 2019 11:28:44 GMT+0900 (Japan Standard Time)
sleep end 1000
sleep end 3000
begin promise all
end Wed Sep 18 2019 11:28:47 GMT+0900 (Japan Standard Time)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0