Created
June 20, 2019 04:05
-
-
Save hiroshi-maybe/d2f61b98554296617989ac72164c0bcb to your computer and use it in GitHub Desktop.
This file contains 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 _ = require('lodash'); | |
const task = (n) => { | |
return new Promise((resolve, reject)=> { | |
setTimeout(() => { | |
console.log("t"+n+" done"); | |
resolve(n); | |
}, 1000*n); | |
}); | |
}; | |
const check = (message) => { | |
return (res) => { | |
console.log(res, 'received'); | |
return new Promise((resolve, reject) => { | |
if(message) console.log(message); | |
resolve(); | |
}); | |
}; | |
}; | |
const seq = () => { | |
return task(1) | |
.then(() => task(2)) | |
.then(() => task(3)) | |
.then(check('completed')); | |
}; | |
const par = () => { | |
return Promise.all([task(1),task(2),task(3)]) | |
.then(check()) | |
.then((xs) => task(4)) | |
.then(check()); | |
}; | |
seq().then(par); | |
//par(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment