Created
March 31, 2019 14:03
-
-
Save mimiz/1e1ff18677df2dd00519c1a865708a4e to your computer and use it in GitHub Desktop.
This file contains 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 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