Skip to content

Instantly share code, notes, and snippets.

@SebastianHGonzalez
Last active January 1, 2019 16:45
Show Gist options
  • Save SebastianHGonzalez/2d67aee7cb850514b9e953715976b0b4 to your computer and use it in GitHub Desktop.
Save SebastianHGonzalez/2d67aee7cb850514b9e953715976b0b4 to your computer and use it in GitHub Desktop.
time aspect using generic aspect implementation
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