Skip to content

Instantly share code, notes, and snippets.

@kenanhancer
Created April 8, 2018 15:48
Show Gist options
  • Save kenanhancer/7e1d85aae3b99419a83130c5519565b2 to your computer and use it in GitHub Desktop.
Save kenanhancer/7e1d85aae3b99419a83130c5519565b2 to your computer and use it in GitHub Desktop.
PromiseTutorial1 created by kenanhancer - https://repl.it/@kenanhancer/PromiseTutorial1
const delay = duration => new Promise(resolve => setTimeout(resolve, duration));
const job1 = async () => {
for (let i = 0; i < 10; i++) {
console.log('*');
await delay(100);
}
};
const job2 = async () => {
for (let i = 0; i < 10; i++) {
console.log('-');
await delay(100);
}
};
const main = async () => {
const [p1, p2] = await Promise.all([job1(), job2()]);
console.log('Finish');
};
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment