Last active
January 27, 2017 18:57
-
-
Save 1999/ce6fd0f3cc6410c392829595c27f7407 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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