Skip to content

Instantly share code, notes, and snippets.

@ayshvab
Created March 8, 2019 16:41
Show Gist options
  • Save ayshvab/af785a04d975bbc99e26b4f98f2120e0 to your computer and use it in GitHub Desktop.
Save ayshvab/af785a04d975bbc99e26b4f98f2120e0 to your computer and use it in GitHub Desktop.
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