Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Created April 20, 2016 15:31
Show Gist options
  • Save ajcrites/d37197a825aada52f285fa8ef308b180 to your computer and use it in GitHub Desktop.
Save ajcrites/d37197a825aada52f285fa8ef308b180 to your computer and use it in GitHub Desktop.
import delay from "timeout-as-promise"
(async () => {
let actions = (new Array(50)).fill(0).map(() => Math.random() * (1000 - 500) + 500);
let promises = [];
try {
actions.forEach(time => promises.push(
async () => {
try {
await delay(0)
console.log("an action completed");
}
catch(err) {
console.log(err);
}
}
// .then(() => console.log("an action completed"))
));
}
catch (err) {
console.log(err);
}
await promises;
})().then(() => console.log("all actions completed"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment