Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Gauge } from './client'
- const observers = new Map()
- export default function <A extends Function> (fn: A, name: string, help: string = ''): A {
- if (!observers.has(name)) {
- observers.set(name, new Gauge({ name, help }))
- }
- const gauge = observers.get(name)
- return new Proxy(fn, {
- apply (target, context, args) {
- const end = gauge.startTimer()
- const result = Reflect.apply(target, context, args)
- if (result instanceof Promise) {
- result.then(() => end())
- } else {
- end()
- }
- return result
- }
- })
- }
Add Comment
Please, Sign In to add comment