Function
time
(
fn: Promise<ReturnType> | (() => ReturnType | Promise<ReturnType>),
{
type,
desc,
timings,
}: {
type: string
desc?: string
timings?: Timings
},
)
Source from the content-addressed store, hash-verified
| 38 | } |
| 39 | |
| 40 | export async function time<ReturnType>( |
| 41 | fn: Promise<ReturnType> | (() => ReturnType | Promise<ReturnType>), |
| 42 | { |
| 43 | type, |
| 44 | desc, |
| 45 | timings, |
| 46 | }: { |
| 47 | type: string |
| 48 | desc?: string |
| 49 | timings?: Timings |
| 50 | }, |
| 51 | ): Promise<ReturnType> { |
| 52 | const timer = createTimer(type, desc) |
| 53 | const promise = typeof fn === 'function' ? fn() : fn |
| 54 | if (!timings) return promise |
| 55 | |
| 56 | const result = await promise |
| 57 | |
| 58 | timer.end(timings) |
| 59 | return result |
| 60 | } |
| 61 | |
| 62 | export function getServerTimeHeader(timings?: Timings) { |
| 63 | if (!timings) return '' |
Tested by
no test coverage detected