Skip to content

Instantly share code, notes, and snippets.

@ryanking8215
Created September 26, 2014 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanking8215/e0278be41de8da06a114 to your computer and use it in GitHub Desktop.
Save ryanking8215/e0278be41de8da06a114 to your computer and use it in GitHub Desktop.
[Promise] 使用递归,按顺序迭代数组异步任务
var array = ['a1','a2','a3','a4']
return (function handle_array(idx){
idx = idx || 0
if (idx>=array.length) {
return
}
return async_task(id,array[idx])
.then(function(result){
idx++;
return handle_array(idx);
})
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment