* Queues a cleanup task and defers timeout selection to a microtask so * multiple synchronous registrations can share one root timer.
(key: unknown, gcTime: number, callback: () => void)
| 28 | * multiple synchronous registrations can share one root timer. |
| 29 | */ |
| 30 | public schedule(key: unknown, gcTime: number, callback: () => void): void { |
| 31 | const executeAt = Date.now() + gcTime |
| 32 | this.tasks.set(key, { executeAt, callback }) |
| 33 | |
| 34 | if (!this.microtaskScheduled) { |
| 35 | this.microtaskScheduled = true |
| 36 | Promise.resolve().then(() => { |
| 37 | this.microtaskScheduled = false |
| 38 | this.updateTimeout() |
| 39 | }) |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | public cancel(key: unknown): void { |
| 44 | this.tasks.delete(key) |
no test coverage detected