Perf: use Bun.peek() to save a few ticks

This commit is contained in:
SukkaW
2024-01-28 22:29:14 +08:00
parent c95e96fc61
commit e626a6b5d2
13 changed files with 108 additions and 47 deletions

View File

@@ -28,6 +28,7 @@ export interface Span {
readonly traceChild: (name: string) => Span,
readonly traceSyncFn: <T>(fn: (span: Span) => T) => T,
readonly traceAsyncFn: <T>(fn: (span: Span) => T | Promise<T>) => Promise<T>,
readonly tracePromise: <T>(promise: Promise<T>) => Promise<T>,
readonly traceResult: TraceResult
}
@@ -83,6 +84,13 @@ export const createSpan = (name: string, parentTraceResult?: TraceResult): Span
},
get traceResult() {
return curTraceResult;
},
async tracePromise<T>(promise: Promise<T>): Promise<T> {
try {
return await promise;
} finally {
span.stop();
}
}
};