Skip to content

Instantly share code, notes, and snippets.

@zeen
Created March 29, 2015 18:50
Show Gist options
  • Save zeen/015df291d0dd02e40072 to your computer and use it in GitHub Desktop.
Save zeen/015df291d0dd02e40072 to your computer and use it in GitHub Desktop.
function event_handler(event)
-- Do stuff
end
module:hook("event", event_handler)
function logger(event, handler_chain)
local r = handler_chain(event);
log("debug", "event %s was handled, the handler returned %s", event, tostring(r));
return r;
end
module:wrap("event", logger)
function benchmarker(event, handler_chain)
local time = gettime();
local r = handler_chain(event);
local diff = gettime() - time;
log("debug", "event %s took %s seconds", event, diff);
return r;
end
module:wrap("event", benchmarker, 10) -- include the logger's time!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment