All files / decorators timer.ts

100% Statements 11/11
0% Branches 0/1
100% Functions 3/3
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 185x 5x   5x 5x 5x   9x 9x 9x 9x 9x 9x          
import * as Debug from 'debug';
const debug = Debug('overland:core');
 
export default function timer(event: string = 'tim') {
  return function(target, key, descriptor) {
    return {
      value: async function(...args: any[]) {
        debug(`${ event }ing`);
        const boot = process.hrtime();
        const res = await descriptor.value.apply(this, args);
        const [ , ns ] = process.hrtime(boot);
        debug(`${ event }ed (took ${ (ns / 1000000).toFixed(3) } ms)`);
        return res;
      }
    };
  };
};