async-operation-hook
An optional observer that fire-and-forget operations report to when they start.
Production code only ever CALLS the hook: notifyAsyncOperationStarted is a no-op until something installs one, so no bookkeeping is kept when nothing is listening. The test support (async-operation-tracking.ts) is what installs it, and it owns the registry of pending operations.
The slot lives on globalThis under a Symbol.for key rather than in a module-level variable. Two installed copies of this module — the code under test bundling one version, the test support depending on another — then still share one slot, so the hook the tests install is the hook the code under test calls. A module-level variable would let each copy keep its own, and tracking would silently see nothing.
The slot is a cross-version wire format: its key and the members of AsyncOperationHook only ever change additively.
Interfaces
Section titled “Interfaces”| Interface | Description |
|---|---|
| AsyncOperationHook | An observer notified whenever a fire-and-forget operation starts. |
Functions
Section titled “Functions”| Function | Description |
|---|---|
| getAsyncOperationHook | Gets the installed AsyncOperationHook. |
| notifyAsyncOperationStarted | Reports a fire-and-forget operation to the installed AsyncOperationHook, if any. |
| setAsyncOperationHook | Installs an AsyncOperationHook, replacing any installed one, or removes it. |
Variables
Section titled “Variables”| Variable | Description |
|---|---|
| ASYNC_OPERATION_HOOK_KEY | The key of the global slot holding the installed AsyncOperationHook. |
| ASYNC_OPERATION_HOOK_VERSION | The version of the AsyncOperationHook shape this copy writes. |