Skip to content

Instantly share code, notes, and snippets.

@jasnell
Created June 11, 2020 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasnell/73e66d445acb5e240d8e7a0028b8b9e8 to your computer and use it in GitHub Desktop.
Save jasnell/73e66d445acb5e240d8e7a0028b8b9e8 to your computer and use it in GitHub Desktop.
const EventEmitter = require('events')
const { promisify } = require('util')
const foo = new EventEmitter()
const sleep = promisify(setTimeout)
foo.on('something', async () => {
await sleep(100)
try {
functionThatDoesNotExist()
} catch (err) {
foo.emit('error', err)
}
})
foo.on('error', (err) => {
throw new Error('boom')
})
foo.emit('something')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment