{"version":3,"file":"index.mjs","names":["__dxlog_file","__dxlog_file","__dxlog_file","__dxlog_file","_decorate","__dxlog_file"],"sources":["../../src/callback.ts","../../src/chain.ts","../../src/cleanup.ts","../../src/debounce.ts","../../src/event-emitter.ts","../../src/mutex.ts","../../src/trigger.ts","../../src/observable.ts","../../src/observable-value.ts","../../src/track-leaks.ts","../../src/task-scheduling.ts","../../src/persistent-lifecycle.ts","../../src/push-iterable.ts","../../src/stream.ts","../../src/stream-to-array.ts","../../src/testing.ts","../../src/timer.ts","../../src/update-scheduler.ts","../../src/yield.ts"],"sourcesContent":["//\n// Copyright 2020 DXOS.org\n//\n\nexport type Awaited<T> = T extends Promise<infer U> ? U : T;\n\n/**\n * Helper to convert a callback based API into a promise based API.\n */\nexport const promiseFromCallback = <T = void>(run: (cb: (error?: Error, value?: T) => void) => void): Promise<T> =>\n  new Promise((resolve, reject) => {\n    run((error, value) => {\n      if (error) {\n        reject(error);\n      } else {\n        resolve(value!);\n      }\n    });\n  });\n","//\n// Copyright 2022 DXOS.org\n//\n\ntype Transform = (...args: any) => Promise<any>;\n\n/**\n * Async reducer iteratively applies functions to the given array of elements.\n */\nexport const chain =\n  <T>(chain: Transform[]) =>\n  async (elements: Promise<T[]>) => {\n    let result = await elements;\n    for (const part of chain) {\n      result = await Promise.all(result.map(async (element) => await part(element)));\n    }\n\n    return result;\n  };\n","//\n// Copyright 2025 DXOS.org\n//\n\nimport { ComplexMap, type PrimitiveProjection } from '@dxos/util';\n\nexport type CleanupFn = () => void;\n\n/**\n * Combine multiple cleanup functions into a single cleanup function.\n * Can be used in effect hooks in conjunction with `addEventListener`.\n */\nexport const combine = (...cleanupFns: (boolean | undefined | CleanupFn | CleanupFn[])[]): CleanupFn => {\n  return () => {\n    cleanupFns\n      .flat()\n      .filter((f): f is CleanupFn => typeof f === 'function')\n      .forEach((cleanupFn) => cleanupFn());\n  };\n};\n\nexport const timeout = (cb: Function, ms = 0): CleanupFn => {\n  const t = setTimeout(cb, ms);\n  return () => clearTimeout(t);\n};\n\nexport const interval = (cb: Function, ms: number): CleanupFn => {\n  const t = setInterval(cb, ms);\n  return () => clearInterval(t);\n};\n\ntype EventMap<T> = T extends Window\n  ? WindowEventMap\n  : T extends Document\n    ? DocumentEventMap\n    : T extends HTMLElement\n      ? HTMLElementEventMap\n      : Record<string, Event>;\n\n/**\n * Add the event listener and return a cleanup function.\n * Can be used in effect hooks in conjunction with `combine`.\n */\nexport const addEventListener = <T extends EventTarget, K extends keyof EventMap<T>>(\n  target: T,\n  type: K,\n  listener: (this: T, ev: EventMap<T>[K]) => any,\n  options?: boolean | AddEventListenerOptions,\n): CleanupFn => {\n  target.addEventListener(type as string, listener as EventListener, options);\n  return () => target.removeEventListener(type as string, listener as EventListener, options);\n};\n\nexport class SubscriptionList {\n  private readonly _cleanups: CleanupFn[] = [];\n\n  add(...cb: CleanupFn[]): this {\n    this._cleanups.push(...cb);\n    return this;\n  }\n\n  clear(): void {\n    this._cleanups.forEach((cb) => cb());\n    this._cleanups.length = 0;\n  }\n}\n\nexport class SubscriptionSet<T = any> {\n  private readonly _cleanupMap: ComplexMap<T, CleanupFn>;\n\n  constructor(keyProjection: PrimitiveProjection<T>) {\n    this._cleanupMap = new ComplexMap<T, CleanupFn>(keyProjection);\n  }\n\n  set(key: T, cb: CleanupFn): this {\n    this._cleanupMap.set(key, cb);\n    return this;\n  }\n\n  clear(): void {\n    this._cleanupMap.forEach((cb) => cb());\n    this._cleanupMap.clear();\n  }\n}\n","//\n// Copyright 2023 DXOS.org\n//\n\ntype Callback = (...args: any[]) => void;\n\n/**\n * Delay callback execution by a specified time.\n * Unlike debounce, subsequent calls during the delay period are ignored.\n *\n * @param cb Callback to invoke.\n * @param delay Time to wait before invoking the callback.\n * @returns A new function that schedules the callback once and ignores subsequent calls until executed.\n */\nexport const delay = <F extends Callback>(cb: F, delay = 100): F => {\n  let pending = false;\n  return ((...args: any[]) => {\n    if (pending) {\n      return;\n    }\n\n    pending = true;\n    setTimeout(() => {\n      try {\n        cb(...args);\n      } finally {\n        pending = false;\n      }\n    }, delay);\n  }) as F;\n};\n\n/**\n * Debounce callback: delays execution until calls stop.\n * Each new call resets the timer, so the callback fires only after the delay elapses with no further calls (trailing-edge).\n * Use when you want to react to the end of a burst of events (e.g. user stops typing).\n *\n * @param cb Callback to invoke.\n * @param delay Idle time (ms) to wait after the last call before invoking.\n * @returns Wrapped function that postpones invocation until activity ceases.\n */\nexport const debounce = <F extends Callback>(cb: F, delay = 100): F => {\n  let t: ReturnType<typeof setTimeout>;\n  return ((...args: any[]) => {\n    clearTimeout(t);\n    t = setTimeout(() => cb(...args), delay);\n  }) as F;\n};\n\n/**\n * Throttle callback: limits execution to at most once per interval.\n * The callback fires immediately on the first call;\n * subsequent calls within the same interval are dropped (leading-edge).\n * Use when you need regular updates at a bounded rate (e.g. scroll or resize handlers).\n *\n * @param cb Callback to invoke.\n * @param delay Minimum interval (ms) between successive invocations.\n * @returns Wrapped function that rate-limits invocations.\n */\nexport const throttle = <F extends Callback>(cb: F, delay = 100): F => {\n  let lastCall = 0;\n  return ((...args: any[]) => {\n    const now = Date.now();\n    if (now - lastCall >= delay) {\n      cb(...args);\n      lastCall = now;\n    }\n  }) as F;\n};\n\n/**\n * Debounce and throttle callback.\n * Executes immediately on the first call (throttle), prevents calls during the throttle window,\n * and ensures a final call happens after activity stops (debounce).\n *\n * @param cb Callback to invoke.\n * @param delay Time window for both throttle and debounce.\n * @returns A new function that combines throttle and debounce behavior.\n */\nexport const debounceAndThrottle = <F extends Callback>(cb: F, delay = 100): F => {\n  let timeout: ReturnType<typeof setTimeout>;\n  let lastCall = 0;\n\n  return ((...args: any[]) => {\n    const now = Date.now();\n    const delta = now - lastCall;\n\n    // Clear any pending debounced call.\n    clearTimeout(timeout);\n\n    // Throttle: execute immediately if enough time has passed.\n    if (delta >= delay) {\n      cb(...args);\n      lastCall = now;\n    } else {\n      // Debounce: schedule to execute after the remaining time.\n      timeout = setTimeout(() => {\n        cb(...args);\n        lastCall = Date.now();\n      }, delay - delta);\n    }\n  }) as F;\n};\n","//\n// Copyright 2020 DXOS.org\n//\n\nimport { type EventEmitter } from 'node:events';\n\nimport { asyncTimeout } from './timeout.ts';\n\n/**\n * Adds the listener and returns a function to remove it.\n * Promotes removing listeners when cleaning up objects (to prevent leaks).\n */\nexport const onEvent = (eventEmitter: EventEmitter, eventName: string, callback: (args: any) => void) => {\n  eventEmitter.on(eventName, callback);\n  return () => eventEmitter.off(eventName, callback);\n};\n\n/**\n * @deprecated\n */\nexport const addListener = (eventEmitter: EventEmitter, eventName: string, callback: () => void) => {\n  const off = onEvent(eventEmitter, eventName, callback);\n  return {\n    remove: () => off(),\n  };\n};\n\n/**\n * Waits for an event with an optional test condition.\n */\nexport const waitForEvent = (\n  eventEmitter: EventEmitter,\n  eventName: string,\n  test?: (args: any) => boolean,\n  timeout?: number,\n  error?: Error | string,\n): Promise<any> => {\n  let off;\n\n  const promise = new Promise((resolve) => {\n    off = onEvent(eventEmitter, eventName, (...args) => {\n      if (!test || test(...args)) {\n        resolve(...args);\n      }\n    });\n  });\n\n  return timeout ? asyncTimeout(promise, timeout, error ?? new Error()).finally(off) : promise.finally(off);\n};\n","//\n// Copyright 2020 DXOS.org\n//\n\n// Import explicit resource management polyfill.\nimport '@dxos/util';\nimport { warnAfterTimeout } from '@dxos/debug';\n\n/**\n * A locking mechanism to ensure that a given section of the code is executed by only one single \"thread\" at a time.\n *\n * Functions are chained in a structure similar to a linked list.\n * `_lastPromise` always contains the function that will finish executing last.\n *\n * Initially it is set to `Promise.resolve()` -- a promise that resolves immediately.\n * Enqueuing is done by attaching provided function to the `_lastPromise` via a `.then()` call\n * then updating the `_lastPromise` variable.\n *\n * It is important that enqueuing is done atomically:\n * there are no `await`s in `executeSynchronized` and it's not async while still returning a promise.\n *\n * Java docs reference on synchronized sections:\n * https://docs.oracle.com/javase/tutorial/essential/concurrency/locksync.html\n */\nexport class Mutex {\n  private _queue = Promise.resolve();\n  private _queueLength = 0;\n\n  private _tag: string | null = null;\n\n  get tag() {\n    return this._tag;\n  }\n\n  isLocked(): boolean {\n    return this._queueLength > 0;\n  }\n\n  /**\n   * Acquires the lock.\n   * Caller is responsible for releasing the lock using the returned callback.\n   * NOTE: Using `executeSynchronized` is preferred over using `acquire` directly.\n   * @returns Release callback\n   */\n  async acquire(tag?: string): Promise<MutexGuard> {\n    const prev = this._queue;\n\n    // Immediately update the promise before invoking any async actions so that next invocation waits for our task to complete.\n    let guard!: MutexGuard;\n    this._queueLength++;\n    this._queue = new Promise((resolve) => {\n      guard = new MutexGuard(() => {\n        this._queueLength--;\n        this._tag = null;\n        resolve();\n      });\n    });\n\n    await prev;\n\n    if (tag !== undefined) {\n      this._tag = tag;\n    }\n    return guard;\n  }\n\n  /**\n   * Waits for all previous executions to complete and then executes a given function.\n   * Only a single function can be executed at a time.\n   * Function are executed in the same order as `executeSynchronized` is called.\n   * WARNING: Calling `executeSynchronized` inside of `executeSynchronized` on the same lock instance is a deadlock.\n   */\n  async executeSynchronized<T>(fun: () => Promise<T>): Promise<T> {\n    const guard = await this.acquire();\n\n    try {\n      return await fun();\n    } finally {\n      guard.release();\n    }\n  }\n}\n\nexport class MutexGuard {\n  constructor(private readonly _release: () => void) {}\n\n  /**\n   * Releases the lock.\n   */\n  release(): void {\n    this._release();\n  }\n\n  [Symbol.dispose](): void {\n    this.release();\n  }\n}\n\nconst classMutexSymbol = Symbol('class-mutex');\n\ninterface LockableClass {\n  [classMutexSymbol]?: Mutex;\n}\n\nconst FORCE_DISABLE_WARNING = false;\n\n// Enabled only in tests by default.\nconst enableWarning = !FORCE_DISABLE_WARNING && (globalThis as any).mochaExecutor;\n\n/**\n * Same as `synchronized` in Java.\n * Uses a lock global to the current class instance.\n * This way every synchronized method on the same instance will share a single lock.\n */\nexport const synchronized = (\n  target: any,\n  propertyName: string,\n  descriptor: TypedPropertyDescriptor<(...args: any) => Promise<any>>,\n) => {\n  const method = descriptor.value!;\n  descriptor.value = async function synchronizedMethod(this: any & LockableClass, ...args: any) {\n    const mutex: Mutex = (this[classMutexSymbol] ??= new Mutex());\n\n    const tag = `${target.constructor.name}.${propertyName}`;\n\n    // Disable warning in prod to avoid performance penalty.\n    let guard;\n    if (!enableWarning) {\n      guard = await mutex.acquire(tag);\n    } else {\n      guard = await warnAfterTimeout(10_000, `lock on ${tag} (taken by ${mutex.tag})`, () => mutex.acquire(tag));\n    }\n\n    try {\n      return await method.apply(this, args);\n    } finally {\n      guard.release();\n    }\n  };\n  Object.defineProperty(descriptor.value, 'name', { value: propertyName + '$synchronized' });\n};\n","//\n// Copyright 2020 DXOS.org\n//\n\nimport { invariant } from '@dxos/invariant';\n\nimport { TimeoutError } from './errors.ts';\nimport { asyncTimeout } from './timeout.ts';\n\n/**\n * Returns a tuple containing a Promise that will be resolved when the resolver function is called.\n * @deprecated Use `Trigger` instead.\n */\nexport const trigger = <T = void>(timeout?: number): [() => Promise<T>, (arg: T) => void] => {\n  // eslint-disable-line prefer-arrow-functions/prefer-arrow-functions\n  let callback: (arg: T) => void;\n\n  const promise = new Promise<T>((resolve, reject) => {\n    if (timeout) {\n      setTimeout(() => reject(new Error(`Timed out after ${timeout.toLocaleString()}ms`)), timeout);\n    }\n\n    callback = resolve;\n  });\n\n  const provider = () => promise;\n  const resolver = (value: T) => callback(value);\n\n  return [provider, resolver];\n};\n\nexport type TriggerOptions = {\n  autoReset: boolean;\n};\n\nexport enum TriggerState {\n  WAITING = 'WAITING',\n  RESOLVED = 'RESOLVED',\n  REJECTED = 'REJECTED',\n}\n\n/**\n * Enables blocked listeners to be awakened with optional timeouts.\n *\n * Has two states:\n * - WAITING: promise is in pending state and will be resolved once `wake()` is called.\n * - RESOLVED: promise is already resolved, and all calls to `wait()` resolve immediately.\n * - REJECTED: promise is rejected, and all calls to `wait()` return rejected promise.\n *\n * Trigger starts in WAITING state initially.\n * Use `reset()` to switch resolved trigger back to WAITING state.\n */\nexport class Trigger<T = void> {\n  private _promise!: Promise<T>;\n  private _resolve!: (value: T | PromiseLike<T>) => void;\n  private _reject!: (error: Error) => void;\n  private _state: TriggerState = TriggerState.WAITING;\n\n  constructor(private _options: TriggerOptions = { autoReset: false }) {\n    this.reset();\n  }\n\n  get state() {\n    return this._state;\n  }\n\n  /**\n   * Wait until wake is called, with optional timeout.\n   */\n  async wait({ timeout }: { timeout?: number } = {}): Promise<T> {\n    if (timeout) {\n      return asyncTimeout(this._promise, timeout, new TimeoutError(timeout));\n    } else {\n      return this._promise;\n    }\n  }\n\n  /**\n   * Wake blocked callers (if any).\n   * NOOP if the trigger is already resolved.\n   */\n  wake(value: T): this {\n    if (this._state !== TriggerState.WAITING) {\n      return this;\n    }\n    this._state = TriggerState.RESOLVED;\n    this._resolve(value);\n    if (this._options.autoReset) {\n      return this.reset();\n    }\n\n    return this;\n  }\n\n  /**\n   * Reset promise (new waiters will wait).\n   */\n  reset(): this {\n    this._state = TriggerState.WAITING;\n    this._promise = new Promise<T>((resolve, reject) => {\n      this._resolve = resolve;\n      this._reject = reject;\n    });\n\n    this._promise.catch(() => {}); // Prevent unhandled promise rejections.\n    return this;\n  }\n\n  /**\n   * Throw error to blocked callers (if any).\n   * NOOP if the trigger is already resolved.\n   */\n  throw(error: Error): this {\n    if (this._state !== TriggerState.WAITING) {\n      return this;\n    }\n    this._state = TriggerState.REJECTED;\n    this._reject(error);\n    if (this._options.autoReset) {\n      return this.reset();\n    }\n\n    return this;\n  }\n}\n\ntype LatchProps = {\n  count?: number;\n  timeout?: number;\n};\n\ntype LatchResult = [() => Promise<number>, () => number, (err: Error) => void];\n\n/**\n * Returns a callback and a promise that's resolved when the callback is called n times.\n * @deprecated Use `Trigger` instead.\n */\nexport const latch = ({ count = 1, timeout }: LatchProps = {}): LatchResult => {\n  invariant(count >= 0);\n\n  let t: ReturnType<typeof setTimeout>;\n  let doResolve: (value: number) => void;\n  let doReject: (err: Error) => void;\n  const promise = new Promise<number>((resolve, reject) => {\n    doResolve = (value) => {\n      clearTimeout(t);\n      resolve(value);\n    };\n\n    doReject = (err) => {\n      clearTimeout(t);\n      reject(err);\n    };\n  });\n\n  if (count === 0) {\n    setTimeout(() => {\n      doResolve(0);\n    });\n  } else {\n    if (timeout) {\n      t = setTimeout(() => {\n        doReject(new Error(`Timed out after ${timeout.toLocaleString()}ms`));\n      }, timeout);\n    }\n  }\n\n  let i = 0;\n  return [\n    async () => await promise,\n    () => {\n      if (++i === count) {\n        doResolve(i);\n      }\n\n      return i;\n    },\n    (err: Error) => doReject(err),\n  ];\n};\n","//\n// Copyright 2023 DXOS.org\n//\n\nimport Observable from 'zen-observable';\nimport type { ObservableLike, Observer, Subscriber } from 'zen-observable/esm';\nimport PushStream from 'zen-push';\n\nimport { type Event } from './events.ts';\nimport { Trigger } from './trigger.ts';\n\nexport { Observable, PushStream, type Subscriber };\n\n// Inspired by:\n// https://github.com/zenparsing/zen-push/blob/39949f1/index.js#L93\n// https://github.com/apollographql/apollo-client/blob/a0eb4d6/src/utilities/observables/Concast.ts\n\n/**\n * Observable which supports multiple subscribers and stores the current value.\n *\n * The current value is emitted to new subscribers on subscription.\n */\nexport class MulticastObservable<T> extends Observable<T> {\n  private readonly _observers = new Set<Observer<T>>();\n  private readonly _observable: Observable<T>;\n  private readonly _completed = new Trigger();\n\n  constructor(\n    subscriber: Observable<T> | Subscriber<T>,\n    protected _value?: T,\n  ) {\n    super((observer) => this._subscribe(observer));\n\n    this._observable = typeof subscriber === 'function' ? new Observable(subscriber) : subscriber;\n    // Automatically subscribe to source observable.\n    // Ensures that the current value is always up to date.\n    // TODO(wittjosiah): Does this subscription need to be cleaned up? Where should that happen?\n    this._observable.subscribe(this._handlers);\n  }\n\n  static override from<T>(\n    value: Observable<T> | ObservableLike<T> | ArrayLike<T> | Event<T>,\n    initialValue?: T,\n  ): MulticastObservable<T> {\n    if ('emit' in value) {\n      return new MulticastObservable((observer) => {\n        // TODO(wittjosiah): Do error/complete matter for events?\n        value.on((data) => {\n          observer.next(data);\n        });\n      }, initialValue);\n    }\n\n    const observable = Observable.from(value);\n    return new MulticastObservable(observable, initialValue);\n  }\n\n  static override of<T>(...items: T[]): MulticastObservable<T> {\n    return new MulticastObservable(Observable.of(...items.slice(1)), items[0]);\n  }\n\n  /**\n   * @returns Stable reference to an observable that always returns `undefined`.\n   */\n  static empty(): MulticastObservable<null> {\n    return EMPTY_OBSERVABLE;\n  }\n\n  /**\n   * Get the current value of the observable.\n   */\n  get(): T {\n    // TODO(wittjosiah): Is there a better way to handle this?\n    //   `this._value` is not guaranteed to be set for compatibility with `Observable` base class.\n    //   `get()` should always return `T` to avoid having to sprinkle conditional logic.\n    if (this._value === undefined) {\n      throw new Error('MulticastObservable is not initialized.');\n    }\n\n    return this._value;\n  }\n\n  /**\n   * Wait for the observable to complete.\n   *\n   * @returns Promise that resolves to the value of the observable at the time of completion.\n   */\n  async wait({ timeout }: { timeout?: number } = {}): Promise<T> {\n    await this._completed.wait({ timeout });\n    return this.get();\n  }\n\n  override forEach(callback: (value: T) => void): Promise<void> {\n    return this._observable.forEach(callback);\n  }\n\n  override map<R>(callback: (value: T) => R): MulticastObservable<R> {\n    return new MulticastObservable(this._observable.map(callback), this._value && callback(this._value));\n  }\n\n  override filter(callback: (value: T) => boolean): MulticastObservable<T> {\n    return new MulticastObservable(\n      this._observable.filter(callback),\n      this._value && callback(this._value) ? this._value : undefined,\n    );\n  }\n\n  override reduce<R = T>(callback: (previousValue: R, currentValue: T) => R, initialValue?: R): MulticastObservable<R> {\n    return new MulticastObservable(\n      initialValue ? this._observable.reduce(callback, initialValue) : this._observable.reduce(callback),\n      initialValue ?? (this._value as R),\n    );\n  }\n\n  override flatMap<R>(callback: (value: T) => MulticastObservable<R>): MulticastObservable<R> {\n    return new MulticastObservable(this._observable.flatMap(callback), this._value && callback(this._value).get());\n  }\n\n  override concat<R>(...observables: Array<Observable<R>>): MulticastObservable<R> {\n    return new MulticastObservable(this._observable.concat(...observables), this._value as R);\n  }\n\n  /**\n   * Concatenates multicast observables without losing the current value.\n   * @param reducer reduces the values of any multicast observables being concatenated into a single value\n   * @param observables observables to concatenate\n   * @returns concatenated observable\n   */\n  losslessConcat<R>(\n    reducer: (currentValue: R, newValues: R[]) => R,\n    ...observables: Array<Observable<R>>\n  ): MulticastObservable<R> {\n    const multicast = observables.filter(\n      (observable): observable is MulticastObservable<R> => observable instanceof MulticastObservable,\n    );\n    const value = reducer(\n      this._value as R,\n      multicast.map((observable) => observable.get()),\n    );\n    return new MulticastObservable(this._observable.concat(...observables), value);\n  }\n\n  private _subscribe(observer: Observer<T>): () => void {\n    if (!this._observers.has(observer)) {\n      this._observers.add(observer);\n    }\n\n    if (this._value !== undefined) {\n      observer.next?.(this._value);\n    }\n\n    return () => {\n      this._observers.delete(observer);\n    };\n  }\n\n  private _handlers: Observer<T> = {\n    next: (value) => {\n      this._value = value;\n      this._observers.forEach((observer) => observer.next?.(value));\n    },\n    error: (err) => {\n      this._observers.forEach((observer) => observer.error?.(err));\n    },\n    complete: () => {\n      this._completed.wake();\n      this._observers.forEach((observer) => observer.complete?.());\n    },\n  };\n}\n\nconst EMPTY_OBSERVABLE = MulticastObservable.of(null);\n","//\n// Copyright 2022 DXOS.org\n//\n\nimport { createSetDispatch } from '@dxos/util';\n\nimport { type CleanupFn } from './cleanup.ts';\n\n/**\n * Return type for processes that support cancellable subscriptions.\n * The handler object implements the observable events.\n * @deprecated\n */\nexport interface ObservableValue<Events, Value = unknown> {\n  value?: Value;\n  setValue(value: Value): void;\n  subscribe(handler: Events): CleanupFn;\n}\n\n/**\n * Provider that manages a set of subscriptions.\n * @deprecated\n */\n// TODO(burdon): Support multiple subscribers.\n//  https://betterprogramming.pub/compare-leading-javascript-functional-reactive-stream-libraries-544163c1ded6\n//  https://github.com/apollographql/apollo-client/tree/main/src/utilities/observables\n//  https://github.com/mostjs/core\nexport class ObservableProvider<Events extends {}, Value = unknown> implements ObservableValue<Events, Value> {\n  protected readonly _handlers = new Set<Events>();\n  private readonly _proxy = createSetDispatch<Events>({\n    handlers: this._handlers,\n  });\n\n  private _value?: Value;\n\n  /**\n   * Proxy used to dispatch callbacks to each subscription.\n   */\n  get callback(): Events {\n    return this._proxy;\n  }\n\n  get value() {\n    return this._value;\n  }\n\n  setValue(value: Value): void {\n    this._value = value;\n  }\n\n  subscribe(handler: Events): CleanupFn {\n    this._handlers.add(handler);\n    return () => {\n      this._handlers.delete(handler);\n    };\n  }\n}\n\n/**\n * @deprecated\n */\nexport interface CancellableObservableEvents {\n  onCancelled?(): void;\n}\n\n/**\n * @deprecated\n */\nexport interface CancellableObservable<\n  Events extends CancellableObservableEvents,\n  Value = unknown,\n> extends ObservableValue<Events, Value> {\n  cancel(): Promise<void>;\n}\n\n/**\n * Implements subscriptions with ability to be cancelled.\n * @deprecated\n */\nexport class CancellableObservableProvider<\n  Events extends CancellableObservableEvents,\n> extends ObservableProvider<Events> {\n  private _cancelled = false;\n\n  constructor(private readonly _handleCancel?: () => Promise<void>) {\n    super();\n  }\n\n  get cancelled() {\n    return this._cancelled;\n  }\n\n  async cancel(): Promise<void> {\n    if (this._cancelled) {\n      return;\n    }\n\n    this._cancelled = true;\n    await this._handleCancel?.();\n    this.callback.onCancelled?.();\n  }\n}\n","//\n// Copyright 2022 DXOS.org\n//\n\nimport { StackTrace } from '@dxos/debug';\nimport { log } from '@dxos/log';\n\nconst enabled = typeof process !== 'undefined' && !!process.env.DX_TRACK_LEAKS;\n\ntype OpenResource = {\n  name: string;\n  openStack: StackTrace;\n};\n\nconst openResources = new Set<OpenResource>();\n\nconst handleSymbol = Symbol('checkLeaksHandle');\n\nexport const trackResource = (resourceProvider: () => OpenResource): (() => void) => {\n  if (!enabled) {\n    return () => {};\n  }\n  const resource = resourceProvider();\n\n  openResources.add(resource);\n\n  return () => {\n    openResources.delete(resource);\n  };\n};\n\n/**\n * Makes sure that the resource is at the end of the test.\n *\n * Example:\n *\n * ```typescript\n * @trackLeaks('open', 'close')\n * class Resource {}\n * ```\n */\nexport const trackLeaks =\n  (open: string, close: string): ClassDecorator =>\n  (target: any) => {\n    if (!enabled) {\n      return;\n    }\n\n    const openMethod = target.prototype[open];\n    const closeMethod = target.prototype[close];\n    if (!openMethod || !closeMethod) {\n      throw new Error(`Cannot find ${open} or ${close} method in ${target.name}`);\n    }\n\n    {\n      target.prototype[open] = async function (this: any, ...args: any) {\n        this[handleSymbol] = trackResource(() => ({\n          name: target.name,\n          openStack: new StackTrace(),\n        }));\n\n        return openMethod.apply(this, args);\n      };\n      Object.defineProperty(target.prototype[open], 'name', { value: open + '$checkLeaks' });\n    }\n\n    {\n      target.prototype[close] = async function (this: any, ...args: any) {\n        this[handleSymbol]?.();\n\n        return closeMethod.apply(this, args);\n      };\n      Object.defineProperty(target.prototype[close], 'name', { value: close + '$checkLeaks' });\n    }\n  };\n\nexport const dumpLeaks = () => {\n  if (!enabled) {\n    return;\n  }\n\n  log.info(`Leaked resources ${openResources.size}:`);\n  for (const resource of openResources) {\n    log.info(`- ${resource.name} at`);\n    log.info(resource.openStack.getStack(1));\n    log.info('\\n');\n  }\n};\n\nif (enabled) {\n  (global as any).dxDumpLeaks = dumpLeaks;\n}\n","//\n// Copyright 2022 DXOS.org\n//\n\nimport { Context, ContextDisposedError } from '@dxos/context';\nimport { StackTrace } from '@dxos/debug';\nimport { type MaybePromise } from '@dxos/util';\n\nimport { trackResource } from './track-leaks.ts';\nimport { Trigger } from './trigger.ts';\n\n/**\n * A task that can be scheduled to run in the next event loop iteration.\n * Could be triggered multiple times, but only runs once.\n * If a new task is triggered while a previous one is running, the next run would occur immediately after the current run has finished.\n */\n// TODO(dmaretskyi): Consider calling `join` on context dispose.\n// TODO(burdon): Add throttling support.\nexport class DeferredTask {\n  private _scheduled = false;\n  private _currentTask: Promise<void> | null = null; // Can't be rejected.\n  private _nextTask = new Trigger();\n\n  constructor(\n    private readonly _ctx: Context,\n    private readonly _callback: () => Promise<void>,\n  ) {}\n\n  get scheduled() {\n    return this._scheduled;\n  }\n\n  /**\n   * Schedule the task to run asynchronously.\n   */\n  schedule(): void {\n    if (this._scheduled) {\n      return; // Already scheduled.\n    }\n\n    scheduleTask(this._ctx, async () => {\n      // The previous task might still be running, so we need to wait for it to finish.\n      //\n      // A single await suffices only because this is the one claim site and `_scheduled` collapses\n      // schedules into one waiter. A second path claiming `_currentTask` directly would let two\n      // callbacks run at once — see dxos/edge#758.\n      await this._currentTask; // Can't be rejected.\n\n      // Reset the flag. New tasks can now be scheduled. They would wait for the callback to finish.\n      this._scheduled = false;\n      const completionTrigger = this._nextTask;\n      this._nextTask = new Trigger(); // Re-create the trigger as opposed to resetting it since there might be listeners waiting for it.\n\n      // Store the promise so that new tasks could wait for this one to finish.\n      this._currentTask = runInContextAsync(this._ctx, () => this._callback()).then(() => {\n        completionTrigger.wake();\n      });\n    });\n\n    this._scheduled = true;\n  }\n\n  /**\n   * Schedule the task to run and wait for it to finish.\n   */\n  async runBlocking(): Promise<void> {\n    if (this._ctx.disposed) {\n      throw new ContextDisposedError();\n    }\n\n    this.schedule();\n    await this._nextTask.wait();\n  }\n\n  /**\n   * Waits for the current task to finish if it is running.\n   * Does not schedule a new task.\n   */\n  async join(): Promise<void> {\n    await this._currentTask;\n  }\n}\n\n// TODO(dmaretskyi): Protyping this an alternative API to DeferredTask.\nexport class AsyncTask {\n  #callback: () => Promise<void>;\n  #ctx?: Context = undefined;\n\n  #scheduled = false;\n  #currentTask: Promise<void> | null = null; // Can't be rejected.\n  #nextTask = new Trigger();\n\n  constructor(callback: () => Promise<void>) {\n    this.#callback = callback;\n  }\n\n  get scheduled() {\n    return this.#scheduled;\n  }\n\n  /**\n   * Context of the resource that owns the task.\n   * When the context is disposed, the task is cancelled and cannot be scheduled again.\n   */\n  open(): void {\n    this.#ctx = new Context();\n  }\n\n  /**\n   * Closes the task and waits for it to finish if it is running.\n   */\n  async close(): Promise<void> {\n    await this.#ctx?.dispose();\n    await this.join();\n    this.#ctx = undefined;\n  }\n\n  [Symbol.asyncDispose](): Promise<void> {\n    return this.close();\n  }\n\n  /**\n   * Schedule the task to run asynchronously.\n   */\n  // TODO(dmaretskyi): Add scheduleAt. Where the earlier time will override the later one.\n  schedule(): void {\n    if (!this.#ctx || this.#ctx.disposed) {\n      throw new Error('AsyncTask not open');\n    }\n\n    if (this.#scheduled) {\n      return; // Already scheduled.\n    }\n\n    scheduleTask(this.#ctx, async () => {\n      // The previous task might still be running, so we need to wait for it to finish.\n      await this.#currentTask; // Can't be rejected.\n\n      if (!this.#ctx || this.#ctx.disposed) {\n        return;\n      }\n\n      // Reset the flag. New tasks can now be scheduled. They would wait for the callback to finish.\n      this.#scheduled = false;\n      const completionTrigger = this.#nextTask;\n      this.#nextTask = new Trigger(); // Re-create the trigger as opposed to resetting it since there might be listeners waiting for it.\n\n      // Store the promise so that new tasks could wait for this one to finish.\n      this.#currentTask = runInContextAsync(this.#ctx, () => this.#callback()).then(() => {\n        completionTrigger.wake();\n      });\n    });\n\n    this.#scheduled = true;\n  }\n\n  /**\n   * Schedule the task to run and wait for it to finish.\n   */\n  async runBlocking(): Promise<void> {\n    if (this.#ctx?.disposed) {\n      throw new ContextDisposedError();\n    }\n\n    this.schedule();\n    await this.#nextTask.wait();\n  }\n\n  /**\n   * Waits for the current task to finish if it is running.\n   * Does not schedule a new task.\n   */\n  async join(): Promise<void> {\n    await this.#currentTask;\n  }\n}\n\nexport const runInContext = (ctx: Context, fn: () => void) => {\n  try {\n    fn();\n  } catch (err: any) {\n    ctx.raise(err);\n  }\n};\n\nexport const runInContextAsync = async (ctx: Context, fn: () => MaybePromise<void>) => {\n  try {\n    await fn();\n  } catch (err: any) {\n    ctx.raise(err);\n  }\n};\n\nexport const scheduleMicroTask = (ctx: Context, fn: () => MaybePromise<void>) => {\n  queueMicrotask(async () => {\n    if (ctx.disposed) {\n      return;\n    }\n    await runInContextAsync(ctx, fn);\n  });\n};\n\nexport const scheduleTask = (ctx: Context, fn: () => MaybePromise<void>, afterMs?: number) => {\n  const clearTracking = trackResource(() => ({\n    name: `task (${fn.name || 'anonymous'})`,\n    openStack: new StackTrace(),\n  }));\n\n  const timeout = setTimeout(async () => {\n    clearDispose();\n    await runInContextAsync(ctx, fn);\n    clearTracking();\n  }, afterMs);\n\n  const clearDispose = ctx.onDispose(() => {\n    clearTracking();\n    clearTimeout(timeout);\n  });\n};\n\n/**\n * Run the task in the next event loop iteration, and then repeat in `interval` ms after the previous iteration completes.\n */\nexport const scheduleTaskInterval = (ctx: Context, task: () => Promise<void>, interval: number) => {\n  const clearTracking = trackResource(() => ({\n    name: `repeating task (${task.name || 'anonymous'})`,\n    openStack: new StackTrace(),\n  }));\n\n  let timeoutId: NodeJS.Timeout;\n\n  const run = async () => {\n    await runInContextAsync(ctx, task);\n    if (ctx.disposed) {\n      return;\n    }\n    timeoutId = setTimeout(run, interval);\n  };\n\n  timeoutId = setTimeout(run, interval);\n  ctx.onDispose(() => {\n    clearTracking();\n    clearTimeout(timeoutId);\n  });\n};\n\nexport const scheduleExponentialBackoffTaskInterval = (\n  ctx: Context,\n  task: () => Promise<void>,\n  initialInterval: number,\n) => {\n  const clearTracking = trackResource(() => ({\n    name: `repeating task (${task.name || 'anonymous'})`,\n    openStack: new StackTrace(),\n  }));\n\n  let timeoutId: NodeJS.Timeout;\n\n  let interval = initialInterval;\n  const repeat = async () => {\n    await runInContextAsync(ctx, task);\n    if (ctx.disposed) {\n      return;\n    }\n    interval *= 2;\n    timeoutId = setTimeout(repeat, interval);\n  };\n\n  timeoutId = setTimeout(repeat, interval);\n  ctx.onDispose(() => {\n    clearTracking();\n    clearTimeout(timeoutId);\n  });\n};\n","//\n// Copyright 2024 DXOS.org\n//\n\nimport { LifecycleState, Resource, cancelWithContext } from '@dxos/context';\nimport { warnAfterTimeout } from '@dxos/debug';\nimport { log } from '@dxos/log';\n\nimport { synchronized } from './mutex.ts';\nimport { DeferredTask } from './task-scheduling.ts';\nimport { sleep } from './timeout.ts';\n\nconst INIT_RESTART_DELAY = 100;\nconst DEFAULT_MAX_RESTART_DELAY = 5000;\n\n/**\n * Minimum duration a connection must stay up before it is considered stable and the backoff is\n * reset. A connection that drops sooner keeps escalating the delay, so an endpoint that accepts\n * then immediately closes the connection cannot produce a zero-delay reconnect loop.\n */\nconst STABLE_CONNECTION_THRESHOLD = 5000;\n\nexport type PersistentLifecycleProps<T> = {\n  /**\n   * Create connection.\n   * If promise resolves successfully, connection is considered established.\n   */\n  start: () => Promise<T | undefined>;\n\n  /**\n   * Reset connection to initial state.\n   */\n  stop: (state: T) => Promise<void>;\n\n  /**\n   * Called after successful start.\n   */\n  onRestart?: () => Promise<void>;\n\n  /**\n   * Maximum delay between restartion attempts.\n   * Default: 5000ms\n   */\n  maxRestartDelay?: number;\n};\n\n/**\n * Handles restarts (e.g. persists connection).\n * Restarts are scheduled with exponential backoff.\n */\nexport class PersistentLifecycle<T> extends Resource {\n  private readonly _start: () => Promise<T | undefined>;\n  private readonly _stop: (state: T) => Promise<void>;\n  private readonly _onRestart?: () => Promise<void>;\n  private readonly _maxRestartDelay: number;\n\n  private _currentState: T | undefined = undefined;\n  private _restartTask?: DeferredTask = undefined;\n  private _restartAfter = 0;\n  private _connectedAt: number | undefined = undefined;\n\n  constructor({ start, stop, onRestart, maxRestartDelay = DEFAULT_MAX_RESTART_DELAY }: PersistentLifecycleProps<T>) {\n    super();\n    this._start = start;\n    this._stop = stop;\n    this._onRestart = onRestart;\n    this._maxRestartDelay = maxRestartDelay;\n  }\n\n  get state() {\n    return this._currentState;\n  }\n\n  @synchronized\n  protected override async _open(): Promise<void> {\n    this._restartTask = new DeferredTask(this._ctx, async () => {\n      try {\n        await this._restart();\n      } catch (err) {\n        // Suppress noise from restarts that race with shutdown.\n        if (this._ctx?.disposed) {\n          return;\n        }\n        log.warn('Restart failed', { err });\n        this._restartTask?.schedule();\n      }\n    });\n\n    try {\n      this._currentState = await this._start();\n      this._connectedAt = Date.now();\n    } catch (err) {\n      // Suppress noise when shutdown was requested while the initial start was in flight.\n      if (this._ctx?.disposed) {\n        return;\n      }\n      log.warn('Start failed', { err });\n      this._restartTask?.schedule();\n    }\n  }\n\n  protected override async _close(): Promise<void> {\n    await this._restartTask?.join();\n    await this._stopCurrentState();\n    this._restartTask = undefined;\n  }\n\n  private async _restart(): Promise<void> {\n    log(`restarting in ${this._restartAfter}ms`, { state: this._lifecycleState });\n\n    // Reset the backoff only if the previous connection stayed up long enough to be considered\n    // stable. A connection that drops shortly after starting must keep escalating the delay,\n    // otherwise reconnects degenerate into a hot loop.\n    if (this._connectedAt !== undefined && Date.now() - this._connectedAt >= STABLE_CONNECTION_THRESHOLD) {\n      this._restartAfter = 0;\n    }\n    this._connectedAt = undefined;\n\n    await this._stopCurrentState();\n    if (this._lifecycleState !== LifecycleState.OPEN) {\n      return;\n    }\n    await cancelWithContext(this._ctx!, sleep(this._restartAfter));\n    this._restartAfter = Math.min(Math.max(this._restartAfter * 2, INIT_RESTART_DELAY), this._maxRestartDelay);\n\n    // May fail if the connection is not established.\n    await warnAfterTimeout(5_000, 'Connection establishment takes too long', async () => {\n      this._currentState = await this._start();\n    });\n\n    this._connectedAt = Date.now();\n    await this._onRestart?.();\n  }\n\n  private async _stopCurrentState(): Promise<void> {\n    if (this._currentState) {\n      try {\n        await this._stop(this._currentState);\n      } catch (err) {\n        log.catch(err);\n      }\n      this._currentState = undefined;\n    }\n  }\n\n  /**\n   * Scheduling restart should be done from outside.\n   */\n  @synchronized\n  async scheduleRestart(): Promise<void> {\n    if (this._lifecycleState !== LifecycleState.OPEN) {\n      return;\n    }\n    this._restartTask!.schedule();\n  }\n}\n","//\n// Copyright 2025 DXOS.org\n//\n\nimport { invariant } from '@dxos/invariant';\n\nimport { Trigger } from './trigger.ts';\n\ninterface PushAsyncIterable<T, TReturn = any> extends AsyncIterable<T, TReturn> {\n  /**\n   * Push a value into the iterable.\n   */\n  next(value: T): void;\n\n  /**\n   * Return a value from the iterable.\n   */\n  return(value?: TReturn): void;\n\n  /**\n   * Throw an error from the iterable.\n   */\n  throw(value?: any): void;\n}\n\n/**\n * Creates an async iterable where the data is pushed by calling methods on the iterable.\n */\nexport const makePushIterable = <T, TReturn = any>(): PushAsyncIterable<T, TReturn> => {\n  const buf: ({ kind: 'next'; value: T } | { kind: 'return'; value: TReturn } | { kind: 'throw'; value?: any })[] = [];\n  const trigger = new Trigger({ autoReset: true });\n\n  return {\n    [Symbol.asyncIterator]() {\n      return {\n        next: async (): Promise<IteratorResult<T, TReturn>> => {\n          while (buf.length === 0) {\n            await trigger.wait();\n          }\n\n          const item = buf.shift();\n          invariant(item);\n\n          switch (item.kind) {\n            case 'next':\n              return { value: item.value, done: false };\n            case 'return':\n              return { value: item.value, done: true };\n            case 'throw':\n              throw item.value;\n          }\n        },\n      };\n    },\n    next: (value: T) => {\n      buf.push({ kind: 'next', value });\n      trigger.wake();\n    },\n    return: (value: TReturn) => {\n      buf.push({ kind: 'return', value });\n      trigger.wake();\n    },\n    throw: (value?: any) => {\n      buf.push({ kind: 'throw', value });\n      trigger.wake();\n    },\n  };\n};\n","//\n// Copyright 2021 DXOS.org\n//\n\nimport { Context } from '@dxos/context';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { type MaybePromise, throwUnhandledError } from '@dxos/util';\n\nimport { Trigger } from './trigger.ts';\n\n/** Narrows a caught `unknown` to `Error` — a thrown value is not guaranteed to be one. */\nconst toCaughtError = (err: unknown): Error => (err instanceof Error ? err : new Error(String(err)));\n\ntype Callbacks<T> = {\n  ctx: Context;\n\n  /**\n   * Advises that the producer is ready to stream the data.\n   * Called automatically with the first call to `next`.\n   */\n  ready: () => void;\n\n  /**\n   * Sends a message into the stream.\n   */\n  next: (message: T) => void;\n\n  /**\n   * Closes the stream.\n   * Optional error can be provided.\n   */\n  close: (err?: Error) => void;\n};\n\ntype Producer<T> = (callbacks: Callbacks<T>) => ((err?: Error) => void) | void;\n\nexport type StreamItem<T> = { ready: true } | { data: T } | { closed: true; error?: Error };\n\n// TODO(burdon): Implement Observable<T> pattern to simplify callbacks.\n// stream.subscribe({\n//   onData: (data: CustomData) => {\n//   },\n//   onOpen: () => {\n//   },\n//   onClose: () => {\n//   },\n//   onError: () => {\n//   }\n// });\n//\n// stream.unsubscribe();\n// await stream.close90:\n\n/**\n * Represents a typed stream of data.\n * In concept it's a Promise that can resolve multiple times.\n * Can only have one subscriber.\n * `close` must be called to clean-up the resources.\n */\nexport class Stream<T> {\n  /**\n   * Consumes the entire stream to the end until it closes and returns a promise with the resulting items.\n   */\n  static consume<T>(stream: Stream<T>): Promise<StreamItem<T>[]> {\n    return new Promise((resolve) => {\n      const items: StreamItem<T>[] = [];\n\n      stream.onReady(() => {\n        items.push({ ready: true });\n      });\n      stream.subscribe(\n        (data) => {\n          items.push({ data });\n        },\n        (error) => {\n          if (error) {\n            items.push({ closed: true, error });\n          } else {\n            items.push({ closed: true });\n          }\n          resolve(items);\n        },\n      );\n    });\n  }\n\n  static async consumeData<T>(stream: Stream<T>): Promise<T[]> {\n    const entries = await Stream.consume(stream);\n    const res: T[] = [];\n    for (const entry of entries) {\n      if ('data' in entry) {\n        res.push(entry.data);\n      } else if ('closed' in entry && entry.closed === true) {\n        if (entry.error) {\n          throw entry.error;\n        } else {\n          break;\n        }\n      }\n    }\n    return res;\n  }\n\n  static async first<T>(stream: Stream<T>): Promise<T | undefined> {\n    return new Promise((resolve, reject) => {\n      stream.subscribe(\n        (data) => {\n          resolve(data);\n          void stream.close();\n        },\n        (error) => {\n          if (error) {\n            reject(error);\n          } else {\n            resolve(undefined);\n          }\n        },\n      );\n    });\n  }\n\n  /**\n   * Maps all data coming through the stream.\n   */\n  static map<T, U>(source: Stream<T>, map: (data: T) => U): Stream<U> {\n    return new Stream(({ ready, next, close }) => {\n      source.onReady(ready);\n      source.subscribe((data) => next(map(data)), close);\n\n      return () => source.close();\n    });\n  }\n\n  /**\n   * Converts Promise<Stream<T>> to Stream<T>.\n   */\n  static unwrapPromise<T>(streamPromise: MaybePromise<Stream<T>>): Stream<T> {\n    if (streamPromise instanceof Stream) {\n      return streamPromise;\n    }\n\n    return new Stream(({ ready, next, close }) => {\n      streamPromise.then(\n        (stream) => {\n          stream.onReady(ready);\n          stream.subscribe(next, close);\n        },\n        (err) => {\n          close(err);\n        },\n      );\n      return () => {\n        streamPromise.then(\n          (stream) => stream.close(),\n          (err) => {\n            /* already handled */\n          },\n        );\n      };\n    });\n  }\n\n  static fromPromise<T>(promise: Promise<T>): Stream<T> {\n    return new Stream(({ ready, next, close }) => {\n      promise.then(\n        (data) => {\n          ready();\n          next(data);\n          close();\n        },\n        (err) => {\n          close(err);\n        },\n      );\n    });\n  }\n\n  private readonly _ctx: Context;\n  private _messageHandler?: (msg: T) => void = undefined;\n  private _closeHandler?: (error?: Error) => void = undefined;\n  private _readyHandler?: () => void = undefined;\n\n  private _isClosed = false;\n  private _closeError: Error | undefined = undefined;\n  private _producerCleanup: ((err?: Error) => void) | undefined = undefined;\n  private _readyPromise: Promise<void>;\n  private _resolveReadyPromise!: () => void;\n  private _isReady = false;\n\n  /**\n   * Buffer messages before subscription. Set to null when buffer is no longer needed.\n   */\n  private _buffer: T[] | null = [];\n\n  constructor(producer: Producer<T>, parentCtx?: Context) {\n    this._readyPromise = new Promise((resolve) => {\n      this._resolveReadyPromise = resolve;\n    });\n\n    this._ctx = new Context({\n      parent: parentCtx,\n      onError: (err) => {\n        if (this._isClosed) {\n          return;\n        }\n\n        this._isClosed = true;\n        this._closeError = err;\n        this._producerCleanup?.(err);\n        this._closeHandler?.(err);\n        void this._ctx.dispose();\n      },\n    });\n    this._ctx.onDispose(() => this.close());\n\n    try {\n      const producerCleanup = producer({\n        ctx: this._ctx,\n\n        ready: () => {\n          this._markAsReady();\n        },\n\n        next: (msg) => {\n          if (this._isClosed) {\n            log('Stream is closed, dropping message.');\n            return;\n          }\n\n          this._markAsReady();\n\n          if (this._messageHandler) {\n            try {\n              this._messageHandler(msg);\n            } catch (err: unknown) {\n              // Stop error propagation.\n              throwUnhandledError(toCaughtError(err));\n            }\n          } else {\n            invariant(this._buffer);\n            this._buffer.push(msg);\n          }\n        },\n\n        close: (err) => {\n          if (this._isClosed) {\n            return;\n          }\n\n          this._isClosed = true;\n          this._closeError = err;\n          this._producerCleanup?.(err);\n          try {\n            this._closeHandler?.(err);\n          } catch (err: unknown) {\n            // Stop error propagation.\n            throwUnhandledError(toCaughtError(err));\n          }\n          void this._ctx.dispose();\n        },\n      });\n\n      if (producerCleanup) {\n        this._producerCleanup = producerCleanup;\n      }\n    } catch (err: unknown) {\n      this._ctx.raise(toCaughtError(err));\n    }\n  }\n\n  private _markAsReady(): void {\n    if (!this._isReady) {\n      this._isReady = true;\n      this._readyHandler?.();\n      this._resolveReadyPromise();\n    }\n  }\n\n  // TODO(burdon): Can this be cancelled?\n  subscribe(onMessage: (msg: T) => void, onClose?: (err?: Error) => void): void {\n    invariant(!this._messageHandler, 'Stream is already subscribed to.');\n    invariant(!this._closeHandler, 'Stream is already subscribed to.');\n    invariant(this._buffer); // Must be not-null.\n\n    for (const message of this._buffer) {\n      try {\n        onMessage(message);\n      } catch (err: unknown) {\n        // Stop error propagation.\n        throwUnhandledError(toCaughtError(err));\n      }\n    }\n\n    this._buffer = null;\n\n    // Stream might have already have been closed.\n    if (this._isClosed) {\n      onClose?.(this._closeError);\n      return;\n    }\n\n    this._messageHandler = onMessage;\n    this._closeHandler = onClose;\n  }\n\n  /**\n   * Resolves when stream is ready.\n   */\n  // TODO(burdon): Gather all callbacks into single observer.\n  waitUntilReady(): Promise<void> {\n    return this._readyPromise;\n  }\n\n  /**\n   * Registers a callback to be called when stream is ready.\n   */\n  onReady(onReady: () => void): void {\n    invariant(!this._readyHandler, 'Stream already has a handler for the ready event.');\n    this._readyHandler = onReady;\n    if (this._isReady) {\n      onReady();\n    }\n  }\n\n  /**\n   * Close the stream and dispose of any resources.\n   */\n  async close(): Promise<void> {\n    if (this._isClosed) {\n      return;\n    }\n\n    this._isClosed = true;\n    this._producerCleanup?.();\n    this._closeHandler?.(undefined);\n    await this._ctx.dispose();\n\n    // Clear function pointers.\n    this._messageHandler = undefined;\n    this._closeHandler = undefined;\n    this._producerCleanup = undefined;\n  }\n}\n\n/**\n * Resolves with the first value the stream emits, then closes it.\n * Rejects if the stream closes first — with the stream's error where it had one — so a caller\n * without a `timeout` cannot wait forever on a stream that will never emit.\n */\nexport const getFirstStreamValue = async <T>(stream: Stream<T>, { timeout }: { timeout?: number } = {}): Promise<T> => {\n  // Closing only what this call subscribed to, since `subscribe` throws on an already-subscribed\n  // stream and closing it there would cut off the existing subscriber.\n  let subscribed = false;\n  try {\n    const trigger = new Trigger<T>();\n    stream.subscribe(\n      (value) => trigger.wake(value),\n      (err) => trigger.throw(err ?? new Error('Stream closed before emitting a value.')),\n    );\n    subscribed = true;\n    return await trigger.wait({ timeout });\n  } finally {\n    if (subscribed) {\n      await stream.close();\n    }\n  }\n};\n","//\n// Copyright 2022 DXOS.org\n//\n\n/**\n * Concatenate a readable stream's data into a single array.\n *\n * From https://github.com/stream-utils/stream-to-array, but does not depend on\n * any-promise which does not work in web workers due to using window in its\n * browser shim.\n */\nexport const streamToArray = (stream: NodeJS.ReadableStream): Promise<any[]> => {\n  let deferred: Promise<any[]>;\n\n  if (!stream.readable) {\n    deferred = Promise.resolve([]);\n  } else {\n    deferred = new Promise((resolve, reject) => {\n      // stream is already ended\n      if (!stream.readable) {\n        return resolve([]);\n      }\n\n      let arr: any[] = [];\n\n      const onData = (doc: any) => {\n        arr?.push(doc);\n      };\n\n      const onEnd = (err: any) => {\n        if (err) {\n          reject(err);\n        } else {\n          resolve(arr);\n        }\n        cleanup();\n      };\n\n      const onClose = () => {\n        resolve(arr);\n        cleanup();\n      };\n\n      const cleanup = () => {\n        arr = [];\n        stream.removeListener('data', onData);\n        stream.removeListener('end', onEnd);\n        stream.removeListener('error', onEnd);\n        stream.removeListener('close', onClose);\n      };\n\n      stream.on('data', onData);\n      stream.on('end', onEnd);\n      stream.on('error', onEnd);\n      stream.on('close', onClose);\n    });\n  }\n\n  return deferred;\n};\n","//\n// Copyright 2020 DXOS.org\n//\n\nimport { sleep } from './timeout.ts';\nimport { Trigger } from './trigger.ts';\n\n/**\n * NOTE: THIS SHOULD ONLY BE USED IN TESTS.\n *\n * Returns a Promise which resolves when `condFn` returns truthy.\n * The value returned by `condFn` is used to resolve the Promise.\n * @param condition Function to call.\n * @param [timeout] How long to wait, in milliseconds (0 = no timeout).\n * @param [interval=10] How frequently to check, in milliseconds.\n */\nexport const waitForCondition = <FunctionType extends (...args: any) => any>({\n  condition,\n  timeout = 0,\n  interval = 10,\n  error,\n  breakOnError = false,\n}: {\n  condition: FunctionType;\n  timeout?: number;\n  interval?: number;\n  error?: Error;\n  breakOnError?: boolean;\n}) => {\n  const stopTime = timeout ? Date.now() + timeout : 0;\n  const trigger = new Trigger<ReturnType<FunctionType>>();\n  const waiter = async () => {\n    // eslint-disable-next-line no-unmodified-loop-condition\n    while (!stopTime || Date.now() < stopTime) {\n      try {\n        // eslint-disable-next-line no-await-in-loop\n        const value = await condition();\n        if (value) {\n          trigger.wake(value);\n          break;\n        }\n      } catch (err: any) {\n        if (breakOnError === true) {\n          trigger.throw(err);\n        }\n      }\n\n      // eslint-disable-next-line no-await-in-loop\n      await sleep(interval);\n    }\n  };\n\n  setTimeout(waiter, 0);\n\n  return trigger.wait({ timeout });\n};\n\nexport type UntilCallback<T> = (resolve: (value: T) => void, reject: (error: Error) => void) => Promise<T> | void;\n\n/**\n * Awaits promise.\n */\nexport const until = <T = void>(cb: UntilCallback<T>, timeout?: number): Promise<T> => {\n  return new Promise((resolve, reject) => {\n    const t =\n      timeout &&\n      setTimeout(() => {\n        reject(new Error(`Timeout after ${t}ms`));\n      }, timeout);\n\n    setTimeout(async () => {\n      try {\n        await cb(\n          (value: T) => {\n            t && clearTimeout(t);\n            resolve(value);\n          },\n          (error: Error) => {\n            t && clearTimeout(t);\n            reject(error);\n          },\n        );\n      } catch (err) {\n        reject(err);\n      }\n    });\n  });\n};\n\n/**\n * Wait until promise resolves.\n */\nexport const untilPromise = <T = void>(cb: () => Promise<T>) => cb();\n\n/**\n * Wait until error is thrown.\n */\nexport const untilError = (cb: () => Promise<any>) => {\n  return new Promise((resolve, reject) => {\n    setTimeout(async () => {\n      try {\n        await cb();\n        reject(new Error('No error was thrown.'));\n      } catch (err) {\n        resolve(err);\n      }\n    });\n  });\n};\n","//\n// Copyright 2023 DXOS.org\n//\n\nimport { Event, type ReadOnlyEvent } from './events.ts';\n\nexport type TimerOptions = { count: number; interval: number; jitter?: number };\n\nexport type TimerCallback = (i: number) => Promise<boolean | void>;\n\n/**\n * Manages callback invocations at a interval with a possible jitter.\n * Note: The interval excludes the running time of the callback.\n */\nexport class Timer {\n  private readonly _state = new Event<boolean>();\n  private _timer?: NodeJS.Timeout;\n  private _count = 0;\n\n  constructor(private readonly _callback: TimerCallback) {}\n\n  get state(): ReadOnlyEvent<boolean> {\n    return this._state;\n  }\n\n  get running() {\n    return !!this._timer;\n  }\n\n  start(options: TimerOptions, cb?: () => void): this {\n    if (isNaN(options.count) || isNaN(options.interval)) {\n      throw new Error(`Invalid options: ${JSON.stringify(options)}`);\n    }\n\n    if (this.running) {\n      this.stop();\n    }\n\n    const stop = () => {\n      this.stop();\n      cb?.();\n    };\n\n    const run = () => {\n      if (this._count >= (options.count ?? 0)) {\n        stop();\n      } else {\n        const interval = (options.interval ?? 0) + Math.random() * (options.jitter ?? 0);\n        this._timer = setTimeout(async () => {\n          await this._callback(this._count++);\n          run();\n        }, interval);\n      }\n    };\n\n    this._state.emit(true);\n    this._count = 0;\n\n    // Start asynchronously (give caller chance to register event listener).\n    setTimeout(run);\n    return this;\n  }\n\n  stop(): this {\n    clearInterval(this._timer);\n    this._timer = undefined;\n    this._state.emit(false);\n    return this;\n  }\n}\n","//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Context } from '@dxos/context';\n\nimport { scheduleMicroTask } from './task-scheduling.ts';\nimport { Trigger, TriggerState } from './trigger.ts';\n\nexport type UpdateSchedulerOptions = {\n  /**\n   * Maximum frequency of updates. If not specified, updates will be scheduled on every change.\n   */\n  maxFrequency?: number;\n};\n\n/**\n * Time period for update counting.\n */\nconst TIME_PERIOD = 1_000;\n\n/** A claimed run's error (or `undefined`). Resolves, never rejects — `runBlocking` re-throws it. */\ntype RunResult = Promise<Error | undefined>;\n\n/**\n * Runs a non-reentrant callback at most once at a time, coalescing triggers (optionally rate-limited\n * via {@link UpdateSchedulerOptions.maxFrequency}).\n *\n * The runner inside {@link trigger} is the only place the callback starts; `runBlocking` and\n * `forceTrigger` funnel into it. That, plus `_scheduled` collapsing triggers into one pending\n * runner, is what makes mutual exclusion hold by construction (dxos/edge#758).\n */\nexport class UpdateScheduler {\n  /** The running pass; never rejects, non-null exactly while a run is executing. */\n  private _currentTask: Promise<void> | null = null;\n  private _scheduled = false;\n\n  /**\n   * Armed by the `trigger` that schedules a runner, woken by that runner when it claims — with the\n   * run's promise, which `Trigger` adopts, so waiters resume when the run *finishes*. Lets\n   * `runBlocking` await a run that does not exist in `_currentTask` yet.\n   *\n   * `reset()` abandons parked waiters, so it may only be armed in `trigger`'s non-coalesced branch:\n   * waiters park only while `_scheduled` is true, and that branch requires it false.\n   */\n  private _runOutcome = new Trigger<RunResult>();\n\n  /** Woken to make the pending runner skip its throttle delay. Replaced at claim time. */\n  private _skipDelay = new Trigger();\n\n  /**\n   * `runBlocking` callers in flight, incremented synchronously before triggering. A failing run uses\n   * it to tell whether someone will throw the error; counting microtask hops to a waiter's resume\n   * would be a race.\n   */\n  private _observers = 0;\n\n  private _lastUpdateTime = -TIME_PERIOD;\n\n  constructor(\n    private readonly _ctx: Context,\n    private readonly _callback: () => Promise<void>,\n    private readonly _params: UpdateSchedulerOptions = {},\n  ) {\n    _ctx.onDispose(async () => {\n      await this._currentTask; // Context waits for callback to finish.\n      // Release `runBlocking` callers parked on a runner that never claimed. NOOP if already woken.\n      this._runOutcome.wake(Promise.resolve(undefined));\n    });\n  }\n\n  get scheduled() {\n    return this._scheduled;\n  }\n\n  /**\n   * Schedule the callback to run asynchronously. Triggers issued while a run is pending or in flight\n   * coalesce into the next run.\n   */\n  trigger(): void {\n    if (this._scheduled) {\n      return;\n    }\n    this._scheduled = true;\n    this._runOutcome.reset(); // Only here — never on a coalesced trigger (see `_runOutcome`).\n\n    // The only claim site. A single await suffices: nothing else claims, so this is the only waiter.\n    scheduleMicroTask(this._ctx, async () => {\n      await this._currentTask; // Never rejects.\n\n      // Rate limiting. Suspending before the claim is safe only because no other claimant exists.\n      if (this._params.maxFrequency) {\n        const now = performance.now();\n        const delay = this._lastUpdateTime + TIME_PERIOD / this._params.maxFrequency - now;\n        // A forced trigger has already woken the skip; awaiting it anyway would still cost the\n        // microtask hops, and a forced run must claim exactly when an unthrottled one would.\n        if (delay > 0 && this._skipDelay.state !== TriggerState.RESOLVED) {\n          const skipDelay = this._skipDelay;\n          await new Promise<void>((resolve) => {\n            const timeoutId = setTimeout(() => {\n              clearContext();\n              resolve();\n            }, delay);\n\n            const clearContext = this._ctx.onDispose(() => {\n              clearTimeout(timeoutId);\n              resolve();\n            });\n\n            // `runBlocking`/`forceTrigger` cut the delay short.\n            void skipDelay.wait().then(() => {\n              clearTimeout(timeoutId);\n              clearContext();\n              resolve();\n            });\n          });\n        }\n      }\n\n      if (this._ctx.disposed) {\n        this._runOutcome.wake(Promise.resolve(undefined));\n        return;\n      }\n\n      // The claim: one synchronous slice from here to the `wake` below.\n      this._scheduled = false;\n      this._skipDelay = new Trigger();\n      this._lastUpdateTime = performance.now();\n      const run: RunResult = this._callback().then(\n        () => undefined,\n        (error): Error => {\n          // A thrown non-Error is typed away here, matching `Context.raise`'s signature.\n          const failure = error as Error;\n          // Unobserved failures go to the context, as trigger-path failures always have.\n          if (this._observers === 0) {\n            this._ctx.raise(failure);\n          }\n          return failure;\n        },\n      );\n      const task: Promise<void> = run.then(() => {\n        if (this._currentTask === task) {\n          this._currentTask = null;\n        }\n      });\n      this._currentTask = task;\n      this._runOutcome.wake(run);\n    });\n  }\n\n  /**\n   * Run as soon as possible: schedules (coalescing with any pending run) and skips the throttle\n   * delay. Does not start a concurrent callback.\n   */\n  forceTrigger(): void {\n    this.trigger();\n    this._skipDelay.wake();\n  }\n\n  /**\n   * Waits for the current task to finish if it is running.\n   * Does not schedule a new task, and does not wait for one that is merely scheduled.\n   */\n  async join(): Promise<void> {\n    await this._currentTask;\n  }\n\n  /**\n   * Ensure a run that observes everything enqueued so far, and wait for it to finish. Waits for the\n   * pending run to claim, then for its result; that run necessarily claims after this call, so its\n   * drain includes everything enqueued before it. Rejects with the run's error so a flush barrier can\n   * see its batch was not handed off. No-op once disposed.\n   */\n  async runBlocking(): Promise<void> {\n    if (this._ctx.disposed) {\n      return;\n    }\n    this._observers++;\n    try {\n      this.trigger();\n      this._skipDelay.wake();\n      const error = await this._runOutcome.wait();\n      if (error !== undefined) {\n        throw error;\n      }\n    } finally {\n      this._observers--;\n    }\n  }\n}\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport { isNode } from '@dxos/util';\n\ntype HostScheduler = { yield?: () => Promise<void> };\n\n/** One channel for every yield: a port per call would leave an open handle behind each one. */\nlet channel: MessageChannel | undefined;\nconst waiting: Array<() => void> = [];\n\nconst yieldViaMessageChannel = (): Promise<void> =>\n  new Promise((resolve) => {\n    if (!channel) {\n      channel = new MessageChannel();\n      channel.port1.onmessage = () => waiting.shift()?.();\n    }\n    waiting.push(resolve);\n    channel.port2.postMessage(undefined);\n  });\n\n/**\n * Resolves in a later task so queued input and rendering get a turn between slices of a long job.\n *\n * `scheduler.yield` keeps the continuation ahead of other same-priority work where the host has it.\n * A message task is the browser fallback because timers are clamped in a hidden tab, which would\n * stall a background sync; Node drains message ports without visiting its timers, so it gets the\n * timer instead.\n */\nexport const yieldToEventLoop = (): Promise<void> => {\n  const scheduler = (globalThis as { scheduler?: HostScheduler }).scheduler;\n  if (scheduler?.yield) {\n    return scheduler.yield();\n  }\n  if (!isNode() && typeof MessageChannel !== 'undefined') {\n    return yieldViaMessageChannel();\n  }\n  return new Promise((resolve) => setTimeout(resolve, 0));\n};\n\n/**\n * Resolves after the tasks already queued have run. {@link yieldToEventLoop} resumes ahead of them where the\n * host has `scheduler.yield`, which suits input but keeps a background loop ahead of queued messages.\n */\nexport const yieldBehindQueuedTasks = (): Promise<void> =>\n  !isNode() && typeof MessageChannel !== 'undefined'\n    ? yieldViaMessageChannel()\n    : new Promise((resolve) => setTimeout(resolve, 0));\n\n/**\n * How eagerly {@link yieldOrContinue} gives the event loop a turn, named after `main-thread-scheduling`'s strategies:\n * the work keeps the page `interactive`, `smooth` or `idle`.\n */\nexport type YieldStrategy = 'interactive' | 'smooth' | 'idle';\n\nconst SLICE_BUDGET_MS: Record<YieldStrategy, number> = { interactive: 83, smooth: 13, idle: 5 };\n\nlet sliceUntilNextTurn: { start: number } | undefined;\n\nconst openSliceUntilNextTurn = (): { start: number } => {\n  if (!sliceUntilNextTurn) {\n    const started = { start: performance.now() };\n    sliceUntilNextTurn = started;\n    void yieldToEventLoop().then(() => {\n      if (sliceUntilNextTurn === started) {\n        sliceUntilNextTurn = undefined;\n      }\n    });\n  }\n  return sliceUntilNextTurn;\n};\n\n/** Whether the current slice has used its strategy's budget, for callers that yield by other means. */\nexport const shouldYield = (strategy: YieldStrategy): boolean =>\n  performance.now() - openSliceUntilNextTurn().start >= SLICE_BUDGET_MS[strategy];\n\n/** Yields to the event loop once the current slice has used its strategy's budget, and resolves at once otherwise. */\nexport const yieldOrContinue = async (strategy: YieldStrategy): Promise<void> => {\n  if (!shouldYield(strategy)) {\n    return;\n  }\n  await yieldToEventLoop();\n};\n"],"mappings":";;;;;;;;;;;;AASA,IAAa,uBAAiC,QAC5C,IAAI,SAAS,SAAS,WAAW;CAC/B,KAAK,OAAO,UAAU;EACpB,IAAI,OACF,OAAO,KAAK;OAEZ,QAAQ,KAAM;CAElB,CAAC;AACH,CAAC;;;;;;ACTH,IAAa,SACP,UACJ,OAAO,aAA2B;CAChC,IAAI,SAAS,MAAM;CACnB,KAAK,MAAM,QAAQ,OACjB,SAAS,MAAM,QAAQ,IAAI,OAAO,IAAI,OAAO,YAAY,MAAM,KAAK,OAAO,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