Last active
August 29, 2015 14:06
-
-
Save pateketrueke/96c0c13ee6d26ee2cda5 to your computer and use it in GitHub Desktop.
This file contains 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
function runTasks(subtasks, callback) { | |
function next() { | |
var task = subtasks.shift(); | |
if (!task) { | |
return callback(); | |
} | |
task(function (err) { | |
if (err) { | |
return callback(err); | |
} | |
next(); | |
}); | |
} | |
next(); | |
} | |
var all = []; | |
[1,2].forEach(function () { | |
all.push(function (next) { | |
console.log('OPEN'); | |
setTimeout(function () { | |
console.log('CLOSE'); | |
next(); | |
}, 2000); | |
}); | |
}); | |
runTasks(all, function (err) { | |
console.log("DONE'EM ALL"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment