close
Close and cleanup resources held by this TrustWeave instance.
Ownership semantics — only components the facade created during TrustWeave.build { ... } are closed; components injected by the caller remain caller-owned and are never touched:
Closed when factory-created: KMS (when resolved from a
keys { provider(...) }name), credential service, revocation manager, trust registry (the instance the configuredTrustRegistryFactorycreated during build), DID method instances registered during build, blockchain anchor clients resolved fromanchor { ... }, the trusted domain manager, and the internal KMS service adapter.Never closed (caller-owned): a KMS supplied via
keys { custom(...) }/customKms(...), a credential service supplied viacredentialService(...), the wallet factory (always supplied viafactories(...)), wallets returned bywallet { ... }(handed to the caller, never retained), and DID methods the caller registers via getDidRegistry after construction.
For each owned component, AutoCloseable.close is invoked when implemented; otherwise, if the component implements PluginLifecycle, stop() + cleanup() are driven.
From a coroutine, call closeAsync instead of this method. AutoCloseable.close cannot suspend, so this method BLOCKS the calling thread until the owned components have stopped. To make that safe it runs the shutdown on a dedicated daemon thread (its own runBlocking event loop, never nested in the caller's dispatcher) and waits for it with a bounded join (60 s); a component that never finishes is logged as an error and abandoned rather than hanging the caller. Even so, never call close() on a single-threaded or main dispatcher from a coroutine: a component that needs that very thread to complete cannot, while it waits here. Use closeAsync (or use { } only from plain, non-coroutine code such as main or a shutdown hook).
Error handling: exceptions thrown by individual components are logged and do not prevent the remaining components from being closed; in keeping with the previous behavior of this method, close() itself never throws. Calling close() more than once is a no-op.
Example:
val trustWeave = TrustWeave.build { ... }
try {
// Use trustWeave
} finally {
trustWeave.close()
}