Skip to content

Instantly share code, notes, and snippets.

@juandopazo
Created March 5, 2013 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juandopazo/5095552 to your computer and use it in GitHub Desktop.
Save juandopazo/5095552 to your computer and use it in GitHub Desktop.
async.js style using YUI promises
function async(args, fn) {
return Y.batch.apply(Y, Y.Array.map(args, function (arg) {
return new Y.Promise(function (resolve, reject) {
fn(arg, function (err, result) {
if (err) {
reject(err);
} else {
resolve(result);
}
});
});
});
}
async(['foo.php', 'bar.php'], Y.io).then(fn);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment