MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / timeAdd

Method timeAdd

packages/db/src/buffers/base-buffer.ts:285–302  ·  view source on GitHub ↗

* Time the body of an `add()` call. Subclasses wrap their work with this * so all add latency is reported uniformly via the `addObserver` hook. * Subclasses may call `reportAddSkipped(reason)` from inside the fn to * mark the call as a no-op (e.g. cached-and-skipped).

(fn: () => Promise<T>)

Source from the content-addressed store, hash-verified

283 * mark the call as a no-op (e.g. cached-and-skipped).
284 */
285 protected async timeAdd<T>(fn: () => Promise<T>): Promise<T> {
286 const start = performance.now();
287 this.inflightAddStats = {};
288 try {
289 return await fn();
290 } finally {
291 try {
292 this.addObserver?.({
293 buffer: this.name,
294 durationMs: performance.now() - start,
295 skipped: this.inflightAddStats.skipped,
296 skipReason: this.inflightAddStats.skipReason,
297 });
298 } catch {
299 // observer errors must not break add
300 }
301 }
302 }
303
304 /** Mark the in-flight add() as a no-op for observability. */
305 protected reportAddSkipped(reason: string) {

Callers 5

addMethod · 0.80
addMethod · 0.80
addMethod · 0.80
addMethod · 0.80
addMethod · 0.80

Calls 1

fnFunction · 0.85

Tested by

no test coverage detected