()
| 23 | } |
| 24 | |
| 25 | export function profiler(): MethodDecorator { |
| 26 | return (target, name: string | symbol, descriptor: PropertyDescriptor): void => { |
| 27 | if (enableProfiler && !!descriptor && typeof descriptor.value === 'function') { |
| 28 | const orig = descriptor.value; |
| 29 | // tslint:disable no-function-expression no-invalid-this |
| 30 | descriptor.value = function (...args: any[]): any { |
| 31 | const start = performance.now(); |
| 32 | const res = orig.bind(this)(...args); |
| 33 | if (isPromise(res)) { |
| 34 | res.then( |
| 35 | (_: any) => { |
| 36 | printCost(start, performance.now(), target.constructor.name, name); |
| 37 | return _; |
| 38 | }, |
| 39 | (err: any) => { |
| 40 | printCost(start, performance.now(), target.constructor.name, name); |
| 41 | throw err; |
| 42 | } |
| 43 | ); |
| 44 | } else { |
| 45 | printCost(start, performance.now(), target.constructor.name, name); |
| 46 | } |
| 47 | return res; |
| 48 | }; |
| 49 | } |
| 50 | }; |
| 51 | } |
| 52 | |
| 53 | type AnyFn = (...args: any[]) => any; |
| 54 |
no test coverage detected