MCPcopy Index your code
hub / github.com/epicweb-dev/epic-stack / time

Function time

app/utils/timing.server.ts:40–60  ·  view source on GitHub ↗
(
	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
40export 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
62export function getServerTimeHeader(timings?: Timings) {
63 if (!timings) return ''

Callers 1

loaderFunction · 0.90

Calls 1

createTimerFunction · 0.85

Tested by

no test coverage detected