Skip to content

Instantly share code, notes, and snippets.

@1999
Last active January 27, 2017 18:57
Show Gist options
  • Save 1999/ce6fd0f3cc6410c392829595c27f7407 to your computer and use it in GitHub Desktop.
Save 1999/ce6fd0f3cc6410c392829595c27f7407 to your computer and use it in GitHub Desktop.
'use strict';
/**
* node --harmony-async-await --trace-opt --trace-deopt test.js | grep 'disabled'
*/
const REJECT_PROBABILITY = 5 / 10000;
const resolveAfterTimeout = (timeout) => {
return new Promise((resolve, reject) => {
if (Math.random() < REJECT_PROBABILITY) {
setTimeout(reject, timeout, new Error(`Error at ${timeout}`));
} else {
setTimeout(resolve, timeout);
}
});
}
const noop = (err) => {
}
const mainWithAsync = async () => {
const promises = [];
for (let i = 0; i < 100; i++) {
promises.push(resolveAfterTimeout(i));
}
try {
await Promise.all(promises);
} catch (err) {
noop(err);
}
}
const mainWithoutAsync = () => {
const promises = [];
for (let i = 0; i < 100; i++) {
promises.push(resolveAfterTimeout(i));
}
Promise.all(promises).catch(noop);
}
mainWithAsync();
// mainWithoutAsync();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment