Skip to content

Instantly share code, notes, and snippets.

@sbimikesmullin
Created February 10, 2015 21:22
Show Gist options
  • Save sbimikesmullin/c5c419c24f7d115d3064 to your computer and use it in GitHub Desktop.
Save sbimikesmullin/c5c419c24f7d115d3064 to your computer and use it in GitHub Desktop.
miniature async
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