Created
February 10, 2021 05:01
-
-
Save lykkin/9113594bcc974dba7768219f865cec67 to your computer and use it in GitHub Desktop.
ez wrapping
This file contains hidden or 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
'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