Skip to content

Commit

Permalink
wip: docs update
Browse files Browse the repository at this point in the history
  • Loading branch information
dnlup committed Dec 13, 2021
1 parent 368d761 commit 9c390ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ It supports Fastify versions `>=3.0.0`.
- [`fastify.hrtime2us(time)`](#fastifyhrtime2ustime)
- [`fastify.hrtime2ms(time)`](#fastifyhrtime2mstime)
- [`fastify.hrtime2s(time)`](#fastifyhrtime2stime)
- [`fastify.timerify(name, fn[, onSend][, opts])`](#fastifytimerifyname-fn-onsend-opts)
- [`fastify.timerify(fn[, options])`](#fastifytimerifyfn-options)
- [Caveats](#caveats)
- [onSend(name, value)](#onsendname-value)
- [Hooks](#hooks)
Expand Down Expand Up @@ -146,12 +146,13 @@ A [utility function](https://github.com/dnlup/hrtime-utils#hrtime2mstime) to con

A [utility function](https://github.com/dnlup/hrtime-utils#hrtime2stime) to convert the legacy `process.hrtime([time])` value to seconds.

### `fastify.timerify(name, fn[, onSend][, opts])`
### `fastify.timerify(fn[, options])`

- `name` [`<string>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type): the label of the metric.
- `fn` [`<Function>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function): the function to time. It can be a sync function, an async function, a function returning a promise, or a constructor. Functions with the callback pattern are not supported.
- `onSend` [`<Function>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function): a custom function to send the timing metric. By default it is a function that send the execution time in millisencods with the passed `name` as label. See the [`onSend`](#onsendname-value) definition.
- `opts` [`<Object>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object): the same options object used to configure the Node core [`timerify`](https://nodejs.org/dist/latest-v16.x/docs/api/perf_hooks.html#performancetimerifyfn-options) function.
- `options` [`<Object>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object): optional configuration options.
- `label` [`<string>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type): the label of the metric, by default is the function name.
- `onSend` [`<Function>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function): a custom function to send the timing metric. By default it is a function that send the execution time in millisencods with the passed `name` as label. See the [`onSend`](#onsendname-value) definition.
- `timerifyOptions` [`<Object>`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object): the same options object used to configure the Node core [`timerify`](https://nodejs.org/dist/latest-v16.x/docs/api/perf_hooks.html#performancetimerifyfn-options) function.

It creates a new function that automatically tracks its execution time and sends the corresponding metric.

Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ declare module 'fastify' {
hrtime2s: (time: [number, number]) => number;
timerify<T extends (...params: any[]) => any>(
fn: T,
opts?: MetricsTimerifyOptions
options?: MetricsTimerifyOptions
): T;
}
}

0 comments on commit 9c390ca

Please sign in to comment.