Kind: Function
Source: src/middleware/timing/timing.ts
Part of: Middleware
Start a timer for the timing middleware.
startTime starts the timer used by the timing middleware. Call it when request handling begins, then retain the returned value so later middleware code can calculate elapsed time.
Signature
tsfunction startTime(c: Context, name: string, description: string)
Parameters
| Name | Type |
|---|---|
c | Context |
name | string |
description | string |
Diagram
mermaidgraph LR Request[Incoming request] --> Start[startTime] Start --> Timer[Stored timer value] Timer --> Handler[Request handler] Handler --> End[Timing middleware records elapsed time]
Usage
tsimport { startTime } from "./src/middleware/timing/timing";
function timingMiddleware(request: Request) {
const timer = startTime();
return handleRequest(request).finally(() => {
recordTiming(timer);
});
}
AI Coding Instructions
- Call
startTimeat the beginning of the middleware execution path. - Keep the returned timer value available until elapsed time is recorded.
- Use the same timer value for all timing calculations associated with a request.
- Keep timer creation separate from response logging or metric submission.
Was this page helpful?