Skip to content

Instantly share code, notes, and snippets.

@ndruger
Created April 26, 2015 14:48
Show Gist options
  • Select an option

  • Save ndruger/413ba4b50555eb03cf3f to your computer and use it in GitHub Desktop.

Select an option

Save ndruger/413ba4b50555eb03cf3f to your computer and use it in GitHub Desktop.
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();
@ndruger
Copy link
Author

ndruger commented Apr 29, 2015

concurrentが正しいか

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