Created
April 26, 2015 14:48
-
-
Save ndruger/413ba4b50555eb03cf3f 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
| limitedParallelAsync = (array, limit, proc) -> | |
| rest = array.concat() | |
| doNext = (res) -> | |
| Promise.resolve() | |
| .then(-> | |
| if rest.length == 0 | |
| return | |
| i = rest.shift() | |
| Promise.resolve() | |
| .then(-> | |
| proc(i) | |
| ) | |
| .then((res) -> | |
| doNext(res) | |
| ) | |
| ) | |
| promises = _.map(_.times(limit), -> | |
| new Promise(-> | |
| doNext() | |
| ) | |
| ) | |
| Promise.all(promises) | |
| limitedParallelAsync(_.times(10), 2, (i) -> | |
| console.log(i) | |
| ) | |
| .done(); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
concurrentが正しいか