Skip to content

basalt / core/src / HookBus

Class: HookBus ​

Defined in: core/src/hooks.ts:25

Constructors ​

Constructor ​

> new HookBus(): HookBus

Returns ​

HookBus

Methods ​

emit() ​

> emit<K>(hook, payload): Promise<void>

Defined in: core/src/hooks.ts:69

Runs the handlers in series, in priority order, then the onAny handlers.

Handlers are ISOLATED (same contract as EventBus.emit): one failure never starves the remaining handlers or the onAny observers (audit/devtools) — every registered handler always runs. Failures still surface to the emitter afterwards: a single failure rethrows the original error, several become an AggregateError. Nothing is ever swallowed silently.

Type Parameters ​

K ​

K extends string

Parameters ​

hook ​

K

payload ​

BasaltHooks[K]

Returns ​

Promise<void>


on() ​

> on<K>(hook, handler, options?): () => void

Defined in: core/src/hooks.ts:30

Registers a handler. Higher priority runs first. Returns an unsubscribe function.

Type Parameters ​

K ​

K extends string

Parameters ​

hook ​

K

handler ​

HookHandler<BasaltHooks[K]>

options? ​
priority? ​

number

Returns ​

() => void


onAny() ​

> onAny(handler): () => void

Defined in: core/src/hooks.ts:52

Subscribes to every hook. Runs after the specific handlers.

Parameters ​

handler ​

AnyHookHandler

Returns ​

() => void

Released under the MIT License.