Skip to content

Instantly share code, notes, and snippets.

@wuqian
Created September 5, 2012 16:45
Show Gist options
  • Save wuqian/3639694 to your computer and use it in GitHub Desktop.
Save wuqian/3639694 to your computer and use it in GitHub Desktop.
js批量异步调用,并发数量控制
var RES_MAX = 10;
var count = 0;
function foo () {
if (count > RES_MAX) {
//出让cpu,等待并发任务完成
return process.nextTick(foo);
}
//do the real work here
count ++;
AAA.save(function(){
count --;
});
return process.nextTick(foo);
}
foo();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment