Skip to content

Instantly share code, notes, and snippets.

@mimiz
Created March 31, 2019 14:03
Show Gist options
  • Save mimiz/1e1ff18677df2dd00519c1a865708a4e to your computer and use it in GitHub Desktop.
Save mimiz/1e1ff18677df2dd00519c1a865708a4e to your computer and use it in GitHub Desktop.
const EventEmitter = require('events');
const myEmitter = new EventEmitter();
let value = 1;
myEmitter.on('event', () => {
setImmediate(() => {
value = 2
});
});
myEmitter.on('event', () => {
setImmediate(() => {
value += 2
});
});
myEmitter.emit('event');
console.log(value); // This will print 1.
setImmediate(() => {
console.log(value); // This will print 4
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment