Skip to content

Instantly share code, notes, and snippets.

@raine

raine/index.js Secret

Last active September 15, 2015 13:35
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 raine/f97f58f680ae71de7218 to your computer and use it in GitHub Desktop.
Save raine/f97f58f680ae71de7218 to your computer and use it in GitHub Desktop.
const measurePromise = (p, cb) => {
const elapsed = hirestime();
p.then(() => cb(elapsed()));
return p;
};
const measurePromiseFn = (fn, cb) =>
(...args) => measurePromise(fn.apply(null, args), cb);
const measure = (metric, fn) =>
measurePromiseFn(fn, (ms) => metrics.timing(metric, ms));
/* or partial(metrics.timing, metric) */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment