Skip to content

Instantly share code, notes, and snippets.

@ukris
Forked from ded/parallel.js
Last active August 29, 2015 14:21
Show Gist options
  • Save ukris/64a0e33aad78644e61d2 to your computer and use it in GitHub Desktop.
Save ukris/64a0e33aad78644e61d2 to your computer and use it in GitHub Desktop.
function parallel() {
var args = Array.apply(null, arguments)
, callback = args.pop()
, returns = []
, len = 0
args.forEach(function (el, i) {
el(function () {
var a = Array.apply(null, arguments)
, e = a.shift()
if (e) return callback(e)
returns[i] = a
if (args.length == ++len) returns.unshift(null) && callback.apply(null, returns)
})
})
}
parallel(
function (fn) {
getTimeline(function (e, timeline) {
fn(e, timeline)
})
}
, function (fn) {
getUser(function (e, user) {
fn(e, user)
})
}
, function (e, timeline, user) {
if (e) return console.log(e)
console.log(timeline, user)
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment