Back to Browser Side Quest
SOURCE / PINNED RELEASE

Made of little things.

Browser Side Quest

Release
b9d42f5768e4…
Author-recorded commit
c267690145fa…
License
LICENSE
Author’s source reference
nostr://npub1ye5ptcxfyyxl5vjvdjar2ua3f0hynkjzpx552mu5snj3qmx5pzjscpknpr/wss%3A%2F%2Fgit.shakespeare.diy%2F/browser-side-quest

Archive hash verified: 6d4b90b8a5f328f7…. The source-to-build association is the author’s claim; it has not been independently rebuilt.

src/sim/scheduler.ts
/**
 * Owns every timer the simulation starts, so a world can be torn down cleanly
 * (host migration, leaving a shard) without stray callbacks firing later.
 */
export class Scheduler {
  private readonly timeouts = new Set<number>();
  private readonly intervals = new Set<number>();

  later(callback: () => void, delay: number): number {
    const handle = globalThis.setTimeout(() => {
      this.timeouts.delete(handle);
      callback();
    }, delay);
    this.timeouts.add(handle);
    return handle;
  }

  cancel(handle: number): void {
    globalThis.clearTimeout(handle);
    this.timeouts.delete(handle);
  }

  every(callback: () => void, period: number): number {
    const handle = globalThis.setInterval(callback, period);
    this.intervals.add(handle);
    return handle;
  }

  dispose(): void {
    for (const handle of this.timeouts) globalThis.clearTimeout(handle);
    for (const handle of this.intervals) globalThis.clearInterval(handle);
    this.timeouts.clear();
    this.intervals.clear();
  }
}