ReadonlydisposedWhether disposal has started.
ReadonlynameDiagnostic name, including the parent path for child scopes.
ReadonlysignalThe owner-supplied lifetime signal. Child scopes share this exact signal; disposing this scope does not abort it.
ReadonlysizeNumber of cleanup entries still held.
Transfers ownership of a distinct, live, unattached child to this scope.
Pass a scope returned by detachedChild; attaching a scope to itself is
invalid. Runtime checks reject values not made by createResourceScope,
double attachment, a disposed child and a disposed parent.
Registers a synchronous cleanup callback. Runs immediately if already
disposed; any exception then propagates to the caller. Do not pass an
async function: TypeScript permits one where void is expected, but its
promise cannot be handled when registration happens after disposal. Use
ResourceScope.deferAsync for every promise-returning callback.
Registers an asynchronous cleanup callback.
Unlike ResourceScope.defer, registering after disposal throws
without invoking cleanup: nothing could await it, so running it here
would only produce an unhandled rejection.
Creates a detached child with the same lifetime signal and a nested
diagnostic name. The caller owns it until attach succeeds.
Disposes every entry in LIFO order, awaiting async cleanups one at a time
so ordering is preserved. Failures are collected, not short-circuited, and
thrown together as a ScopeCleanupError. Calling twice returns the
same promise.
Reports what this scope and its attached children still hold. Safe to call while disposal is in progress, which is exactly when a shutdown that ran out of budget wants to know.
Takes ownership of a disposable resource and returns it unchanged.
A dispose() that returns a promise is awaited in place during teardown,
so ordering holds and a rejection is collected like any other cleanup
failure. Prefer deferAsync when the intent is async teardown — it says so
at the registration site, where a reader is looking.
Owning into an already-disposed scope disposes the resource immediately. That path cannot await anything, so an async disposal there throws after claiming the promise's rejection. A synchronous disposal that throws propagates to the caller.
Owns resource cleanups, including teardown that must be awaited: services, connections, flushes and closes. Use
deferAsyncfor a promise-returning cleanup callback;deferis the synchronous convenience path, andowntakes a disposable whose own teardown may be either.Kept separate from
RegistrationScopeso that stopping can close ingress synchronously first, then drain async work under a budget.Example