Skip to content

Commit

Permalink
fix(timeline): error tolerant promising checking
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jul 20, 2023
1 parent 414ad1c commit 762a669
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/devtools-kit/src/_types/timeline-metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface TimelineEventFunction {
args?: any[]
result?: any
stacktrace?: StackFrame[]
isPromise?: boolean
}

export interface TimelineEventRoute {
Expand Down
18 changes: 11 additions & 7 deletions packages/devtools/src/runtime/function-metrics-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,18 @@ export function __nuxtTimelineWrap(name: string, fn: any) {
metrics.events.push(event)
const result = fn.apply(this, args)
// handle promises
if (result && 'then' in result && typeof result.then === 'function') {
return result
.then((i: any) => i)
.finally(() => {
event.end = Date.now()
return result
})
try {
if (result && typeof result.then === 'function') {
event.isPromise = true
return result
.then((i: any) => i)
.finally(() => {
event.end = Date.now()
return result
})
}
}
catch (e) {}
event.end = Date.now()
return result
}
Expand Down

0 comments on commit 762a669

Please sign in to comment.