timing
Measures fn under name for the request that is running (getRequestEvent().timing.measure): the same as event.timing.measure, for code that has no event at hand.
Measures fn under name for the request that is running (getRequestEvent().timing.measure): the same as
event.timing.measure, for code that has no event at hand. With serverTiming off it only runs fn.
Import#
ts
import { timing } from "@shadow-js/dusk/server";
Signature#
ts
function timing<T>(name: string, fn: () => T, description?: string): T
Parameters#
| Name | Description |
|---|---|
name |
A metric name: a token of 1 to 64 characters that is not total, route, loaders or render. |
fn |
The work. A promise is measured until it settles. |
description |
An optional label. |
Returns#
What fn returns.
Throws#
- Error outside a request; TypeError for an invalid name.
Examples#
ts
import { timing } from "@shadow-js/dusk/server";
const user = await timing("db", () => loadUser(id), "load user");