@kkdev92/vscode-ext-kit - v4.1.1
    Preparing search index...

    Interface ResourceScope

    Owns resource cleanups, including teardown that must be awaited: services, connections, flushes and closes. Use deferAsync for a promise-returning cleanup callback; defer is the synchronous convenience path, and own takes a disposable whose own teardown may be either.

    Kept separate from RegistrationScope so that stopping can close ingress synchronously first, then drain async work under a budget.

    const scope = createResourceScope('projects', { signal });
    scope.deferAsync(() => connection.close());
    await scope.dispose();
    interface ResourceScope {
        disposed: boolean;
        name: string;
        signal: AbortSignal;
        size: number;
        attach(child: ResourceScope): void;
        defer(cleanup: () => void): void;
        deferAsync(cleanup: () => Promise<void>): void;
        detachedChild(name: string): ResourceScope;
        dispose(): Promise<void>;
        inspect(): ScopeInspection;
        own<T extends Registration>(resource: T): T;
    }
    Index
    disposed: boolean

    Whether disposal has started.

    name: string

    Diagnostic name, including the parent path for child scopes.

    signal: AbortSignal

    The owner-supplied lifetime signal. Child scopes share this exact signal; disposing this scope does not abort it.

    size: number

    Number 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.

      Parameters

      Returns void

    • 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.

      Parameters

      • cleanup: () => void

      Returns void

    • 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.

      Parameters

      • cleanup: () => Promise<void>

      Returns void

    • 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.

      Returns Promise<void>

    • 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.

      Type Parameters

      Parameters

      • resource: T

      Returns T