| 3 | // Polyfill for detecting async functions without relying on Node's "util/types" |
| 4 | // Works in Node and browser builds. |
| 5 | const isAsyncFunction = (fn: unknown): fn is (...args: any[]) => Promise<any> => { |
| 6 | if (typeof fn !== "function") { |
| 7 | return false; |
| 8 | } |
| 9 | // Reliable brand check |
| 10 | const tag = Object.prototype.toString.call(fn); |
| 11 | if (tag === "[object AsyncFunction]") { |
| 12 | return true; |
| 13 | } |
| 14 | // Fallback via constructor name (covers most environments) |
| 15 | const ctorName = (fn as any)?.constructor?.name; |
| 16 | return ctorName === "AsyncFunction"; |
| 17 | }; |
| 18 | |
| 19 | export class Trace { |
| 20 | private readonly traceTotals: {[name: string]: {calls: number, totalRuntime: number}} = {}; |