Last active
July 27, 2022 08:53
-
-
Save wbarcovsky/db923286278884d74714b16332754523 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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