Skip to content

Instantly share code, notes, and snippets.

@huyinghuan
Last active March 27, 2016 06:50
Show Gist options
  • Save huyinghuan/8c07df0a4ec4e589a9e6 to your computer and use it in GitHub Desktop.
Save huyinghuan/8c07df0a4ec4e589a9e6 to your computer and use it in GitHub Desktop.
async
async = (queue, over)->
next = ->
step = queue.shift()
if step
step.apply(null, arguments.concat(next))
else
over and over()
next()
var async = (queue, over)=>{
var next = (...args)=>{
let step = queue.shift();
if(step){
let arg = args.concat(next);
step.apply(null, arg)
}else{
over()
}
};
next()
};
var async = function(queue, over){
var next = function(){
var step = queue.shift();
if(step){
step.apply(null, arguments.concat(next));
}else{
over && over();
}
}
}
var whilist = (judgeFn, task, finishAll)=>{
if(!judgeFn()){return finishAll();}
task(()=> whilist(judgeFn, task, finishAll))
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment