# batch

`batch(callback)` runs a synchronous callback and returns its result. Writes are
readable immediately, nested batches share the outer batch, and affected
consumers are notified at most once when the outer callback exits.

If the callback throws, completed writes remain committed and notifications
flush before the callback error is rethrown. Pibbl event dispatches use the same
batching boundary automatically.

Related types: [`Signal`](/reference/types/canvas-runtime/#signal) and
[`WritableSignal`](/reference/types/canvas-runtime/#writablesignal).

## API details from source

<span id="api-batch"></span>

Runs a synchronous callback while coalescing signal notifications until the outer batch
completes.

```ts
batch: <T>(callback: () => T) => T
```

Related API: [batch](/reference/functions/batch/).

### Parameters

- **`callback`** — Synchronous work whose signal notifications are grouped.

### Returns

The callback's return value.

### See also

[signal](/reference/functions/signal/)

[computed](/reference/functions/computed/)

[WritableSignal](/reference/types/canvas-runtime/#writablesignal)

[View source — packages/core/src/lib/signals/graph.ts:367](/source/packages/core/src/lib/signals/graph-ts/#L367)

## Implementation guidance for agents

Read the [Authoring, signals, and lifecycle companion](/agents/topics/lifecycle/) for ownership, adaptation, failure modes, and verification. [Agent start](/agents/) provides the version-selection workflow.

## Complete minimal examples

- [Read and update signals](/minimal-examples/lifecycle/signals/): Use writable, readonly, and computed values with synchronous batching. [Plain source](/minimal/lifecycle/signals.ts)
## Documentation version

Documentation built with @pibbl/core 0.0.2, revision 272a94a. ALPHA — NOT FOR PRODUCTION USE.
