Created
April 8, 2018 15:48
-
-
Save kenanhancer/7e1d85aae3b99419a83130c5519565b2 to your computer and use it in GitHub Desktop.
PromiseTutorial1 created by kenanhancer - https://repl.it/@kenanhancer/PromiseTutorial1
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
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