{"version":3,"sources":["../src/_utils.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\n\nexport class PeriodicCollector<T> {\n  private duration: number;\n  private callback: (value: T) => void;\n  private lastFlushTime: number;\n  private total: T | null = null;\n\n  constructor(callback: (value: T) => void, options: { duration: number }) {\n    /**\n     * Create a new periodic collector that accumulates values and calls the callback\n     * after the specified duration if there are values to report.\n     *\n     * @param callback Function to call with accumulated value when duration expires\n     * @param options.duration Time in seconds between callback invocations\n     */\n    this.duration = options.duration;\n    this.callback = callback;\n    this.lastFlushTime = performance.now() / 1000; // Convert to seconds\n  }\n\n  push(value: T): void {\n    /**\n     * Add a value to the accumulator\n     */\n    if (this.total === null) {\n      this.total = value;\n    } else {\n      // Type assertion needed for generic addition\n      this.total = (this.total as any) + (value as any);\n    }\n\n    if (performance.now() / 1000 - this.lastFlushTime >= this.duration) {\n      this.flush();\n    }\n  }\n\n  flush(): void {\n    /**\n     * Force callback to be called with current total if non-zero\n     */\n    if (this.total !== null) {\n      this.callback(this.total);\n      this.total = null;\n    }\n    this.lastFlushTime = performance.now() / 1000;\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIO,MAAM,kBAAqB;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAkB;AAAA,EAE1B,YAAY,UAA8B,SAA+B;AAQvE,SAAK,WAAW,QAAQ;AACxB,SAAK,WAAW;AAChB,SAAK,gBAAgB,YAAY,IAAI,IAAI;AAAA,EAC3C;AAAA,EAEA,KAAK,OAAgB;AAInB,QAAI,KAAK,UAAU,MAAM;AACvB,WAAK,QAAQ;AAAA,IACf,OAAO;AAEL,WAAK,QAAS,KAAK,QAAiB;AAAA,IACtC;AAEA,QAAI,YAAY,IAAI,IAAI,MAAO,KAAK,iBAAiB,KAAK,UAAU;AAClE,WAAK,MAAM;AAAA,IACb;AAAA,EACF;AAAA,EAEA,QAAc;AAIZ,QAAI,KAAK,UAAU,MAAM;AACvB,WAAK,SAAS,KAAK,KAAK;AACxB,WAAK,QAAQ;AAAA,IACf;AACA,SAAK,gBAAgB,YAAY,IAAI,IAAI;AAAA,EAC3C;AACF;","names":[]}