Updates

View as Markdown

The updates client provides a real-time event stream for your organization. Use it to react to runtime state changes, operation completions, and other events without polling.

Access via bctrl.updates.

stream(signal?)

Subscribe to a real-time event stream. Returns an async generator that yields events as they occur.

1const controller = new AbortController();
2
3for await (const event of bctrl.updates.stream(controller.signal)) {
4 console.log(event.type, event.data);
5
6 if (event.type === "runtime.stopped") {
7 break;
8 }
9}
ParameterTypeRequiredDescription
signalAbortSignalNoAbort signal to cancel the stream

Returns AsyncGenerator<UpdateEvent> — yields events until the stream ends or is aborted.

The stream uses Server-Sent Events (SSE) under the hood, with automatic reconnection.


Example: waiting for a runtime to stop

1async function waitForStop(runtimeAlias: string) {
2 const controller = new AbortController();
3
4 for await (const event of bctrl.updates.stream(controller.signal)) {
5 if (
6 event.type === "runtime.stopped" &&
7 event.data.alias === runtimeAlias
8 ) {
9 controller.abort();
10 return event.data;
11 }
12 }
13}