Skip to content

Instantly share code, notes, and snippets.

@lykkin
Created February 10, 2021 05:01
Show Gist options
  • Save lykkin/9113594bcc974dba7768219f865cec67 to your computer and use it in GitHub Desktop.
Save lykkin/9113594bcc974dba7768219f865cec67 to your computer and use it in GitHub Desktop.
ez wrapping
'use strict'
const Emitter = require('events')
const oldEmitter = Emitter.prototype.emit
Emitter.prototype.emit = function wrappedEmit(ev) {
const start = Date.now()
const res = oldEmitter.apply(this, arguments)
console.log(`emitting ${ev} on ${this.constructor} took ${Date.now() - start} ms`)
return res
}
const x = new Emitter()
x.on('testing', function timeWaster() {
const start = Date.now()
while (Date.now() - start < 1000) {}
})
x.emit('testing')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment