Skip to content

Instantly share code, notes, and snippets.

@wbarcovsky
Last active July 27, 2022 08:53
Show Gist options
  • Select an option

  • Save wbarcovsky/db923286278884d74714b16332754523 to your computer and use it in GitHub Desktop.

Select an option

Save wbarcovsky/db923286278884d74714b16332754523 to your computer and use it in GitHub Desktop.
async function sleep(time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
async function PromiseAll(args) {
args.forEach(async func => {
await func();
});
}
async function test1(delay) {
console.log('a1');
await sleep(delay);
console.log('b1');
await sleep(delay);
console.log('c1');
}
async function test2(delay) {
console.log('a2');
await sleep(delay);
console.log('b2');
await sleep(delay);
console.log('c2');
}
async function main() {
console.log('start');
await Promise.all([test1(100), test2(100)]);
//await PromiseAll([test1(100), test2(100)])
console.log('end');
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment