Skip to content

Instantly share code, notes, and snippets.

@a-eid
Created October 27, 2018 17:27
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 a-eid/d5a6e420d1c68151e00c6bf3a84f85eb to your computer and use it in GitHub Desktop.
Save a-eid/d5a6e420d1c68151e00c6bf3a84f85eb to your computer and use it in GitHub Desktop.
import EventEmitter from "events"
import fs from "fs"
class WithTime extends EventEmitter {
execute(asyncFunc, ...args) {
console.time("execute")
asyncFund(...args, (err, data) => {
if (err) return this.emit("error", err)
this.emit("data", data)
console.timeEnd("execute")
this.emit("end")
})
}
}
const withTime = new WithTime()
withTime.on("begin", () => {})
withTime.on("end", () => {})
withTime.execute(fs.readFile, __filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment