Skip to content

Instantly share code, notes, and snippets.

@qubyte
Last active September 28, 2015 12:52
Show Gist options
  • Save qubyte/0ec81ab787ce737a3bd5 to your computer and use it in GitHub Desktop.
Save qubyte/0ec81ab787ce737a3bd5 to your computer and use it in GitHub Desktop.
const promises = ['some promises in here'];
const waitForPromises = asyncRunner(function* (promises) {
for (const promise of promises) {
yield promise;
}
// At this point all the promises have resolved.
});
// vs
const waitForPromises = asyncRunner(function* (promises) {
yield Promise.all(promises);
// At this point all promises have resolved.
});
// Bonus... async-await just progressed to stage 3, so one day (or now with babel) you'll be able to do this:
const waitForPromises = async function (promises) {
for (const promise of promises) {
await promise;
}
};
// or
const waitForPromises = async function (promises) {
await Promise.all(promises);
};
// but that's obviously redundant.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment