Skip to main content

Function: closeAll()

closeAll(...roots): Promise<void>

Defined in: packages/core/src/close.ts:45

Close every processable reachable from roots, the roots included.

A node that owns nothing does not implement close() and is skipped, so this is safe to point at a whole composition — closeAll(pipeline) finds the one resource-owning node on step three without the caller knowing it is there.

Nodes are visited once even when several roots share one, so a crew whose agents were built from the same node releases it once.

Closes are issued concurrently. No node's teardown depends on another still being up, and a release can be a round trip to something remote — sequencing a ten-agent crew would make teardown ten times the wait for no ordering anyone asked for. A node that does need an order enforces it inside its own close().

Every node is closed even when an earlier one throws; the failures are rethrown together as a CloseFailedError. Stopping at the first failure would leak exactly the resources this exists to release.

Parameters

roots

...Processable<unknown, unknown>[]

Returns

Promise<void>

Example

const crewSession = await crew.start('Ship the auth feature');
const result = await crewSession.stop(); // ends the conversation
await crew.dispose(); // releases what the crew owns

// Directly, for anything you built yourself — including the agents you
// handed a crew, which it deliberately leaves alone:
await closeAll(myPipeline, ...myBots);