Created
February 10, 2015 21:22
-
-
Save sbimikesmullin/c5c419c24f7d115d3064 to your computer and use it in GitHub Desktop.
miniature async
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
module.exports = | |
class async | |
@serial: (a, cb) -> | |
return cb() unless a.length | |
a.push cb | |
(next = (err, result) -> | |
if err or 1 is a.length | |
a[a.length-1] err, result | |
a = [] | |
return | |
a.shift() next | |
return | |
)() | |
return | |
@parallel: (a, cb) -> | |
return cb() unless a.length | |
a.push cb | |
next = (err) -> | |
a.shift() | |
if err or 1 is a.length | |
a[a.length-1] err | |
a = [] | |
return | |
for i of a when i < a.length-1 | |
a[i] next | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment