Skip to content

Instantly share code, notes, and snippets.

@mgtitimoli
Last active August 29, 2015 14:24
Show Gist options
  • Save mgtitimoli/d7a9b94ab64a21f4cb57 to your computer and use it in GitHub Desktop.
Save mgtitimoli/d7a9b94ab64a21f4cb57 to your computer and use it in GitHub Desktop.
Promise based parallel task executor
"use strict";
function parallel(tasks, ...args) {
let error;
let results = [];
for (let curTask of tasks) {
try {
results.push(curTask(...args));
}
catch(e) {
error = e;
break;
}
}
if (error) {
return Promise.reject(error);
}
return Promise.all(results);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment