Last active
February 12, 2016 12:18
-
-
Save artemave/6eec0e0ecb8a149e2360 to your computer and use it in GitHub Desktop.
Batches of concurrent jobs with js promises
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
| var http = require('httpism'); | |
| var _ = require('underscore'); | |
| var p1 = () => http.get('http://google.com').then(() => console.log('p1')) | |
| var p2 = () => http.get('http://google.com').then(() => console.log('p2')) | |
| var p3 = () => http.get('http://google.com').then(() => console.log('p3')) | |
| var p4 = () => http.get('http://google.com').then(() => console.log('p4')) | |
| var a1 = () => Promise.all([p1(), p2()]).then(() => console.log('a1')) | |
| var a2 = () => Promise.all([p3(), p4()]).then(() => console.log('a2')) | |
| _.reduce([a1, a2], (seq, p) => seq.then(p), Promise.resolve()).then(() => console.log("THE END")) | |
| // `reduce` is the same as: | |
| // Promise.resolve().then(a1).then(a2).then(() => console.log("THE END")) | |
Author
artemave
commented
Feb 12, 2016

Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment