Last active
January 1, 2019 16:45
-
-
Save SebastianHGonzalez/2d67aee7cb850514b9e953715976b0b4 to your computer and use it in GitHub Desktop.
time aspect using generic aspect implementation
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
function timeAspect(joinPoint, logger) { | |
const timer = { | |
start: function () { this.startTime = Date.now() }, | |
stop: function () { this.stopTime = Date.now() }, | |
time: function () { return this.stopTime - this.startTime } | |
}; | |
function before() { timer.start() } | |
function after() { timer.stop(), logger.log(timer.time) } | |
return aspect(joinPoint, { before, after }) | |
} | |
expensiveCalculation = timeAspect(expensiveCalculation, console); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment