Created
March 8, 2019 16:41
-
-
Save ayshvab/af785a04d975bbc99e26b4f98f2120e0 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
const EventEmmitter = require('events'); | |
async function test(val) { console.log('A', val) } | |
setImmediate(() => console.log('B')); | |
const ee = new EventEmmitter(); | |
ee.on('foo', async (val) => { | |
process.nextTick(() => test(val), val++); | |
await test(val++); | |
test(val); | |
}); | |
new Promise((res) => { | |
for (let i = 0; i < 1e9; i++) {} | |
setImmediate(() => console.log('C')); | |
process.nextTick(() => res('D')); | |
console.log('E'); | |
}).then(console.log); | |
process.nextTick(() => console.log('F')); | |
(async (res) => { | |
for (let i = 0; i < 1e6; i++) {} | |
process.nextTick(() => console.log('G')); | |
console.log('I') | |
return 'H'; | |
})().then(console.log); | |
process.nextTick(() => console.log('I')); | |
const promises = []; | |
let n = 0; | |
for (; n < 10; n++) promises.push(test(n)) | |
setTimeout((val) => ee.emit('foo', val), 1000, n); | |
ee.emit('foo', 123) | |
console.log('J'); | |
Promise.all(promises); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment