Node / Raster Batch Output · guide
Batch & chain
Current Apexify.js 6.0.0 documentation for Batch & chain.
painter.batch runs independent canvas / image / text jobs with bounded concurrency and preserves input order in the returned Buffer[]. painter.chain runs named painter methods sequentially, passing the previous step’s Buffer into the next when you use the placeholder 'current' or { __isCurrentBuffer: true }.
Types: BatchOperation, ChainOperation, BatchChainAssetOpts (lib-next/types/batch.ts, lib-next/batch/batch-operations.ts).
batch(operations, opts?)
| Field | Meaning |
|---|---|
operations | Non-empty array of { type, config }, bounded by the configured batch-operation resource limit. |
opts.resolveAssetRefs | When true, operation configs are resolved through the shared asset-reference engine. opts.resolve must be available; ApexPainter normally wires its asset resolver for you. |
opts.concurrency | Optional positive integer. The effective value may not exceed the runtime maxBatchConcurrency limit. When omitted, Apexify uses that configured limit. |
opts.signal | Optional AbortSignal. A pre-aborted signal rejects immediately; aborting during a batch stops scheduling additional work and rejects the batch. |
Operation types
type | Behaviour |
|---|---|
canvas | await painter.createCanvas(config) → returns canvasResult.buffer. |
image | Builds a temporary 800×600 canvas, then calls createImage(config, baseCanvas). |
text | Uses the same temporary-canvas pattern with createText(config, baseCanvas). |
Failure semantics
batch is fail-fast at the Promise boundary: if an operation fails, the returned Promise rejects with the failing operation index/type. Results are not returned as a partial array. Work that already started may finish, but the scheduler stops taking new work after failure or cancellation is observed.
chain(operations, opts?)
Each step is { method: string; args: unknown[] }.
method | Resolution |
|---|---|
| Top-level name | painter[method] and it must be a function. |
Dotted path, e.g. path2d.draw | Walks painter properties, so facet methods are supported. |
Args, asset resolution, and cancellation
'current'or{ __isCurrentBuffer: true }is replaced by thecurrentBufferfrom the previous successful step. On the first step it isundefinedunless you pass a real buffer yourself.- With
resolveAssetRefs: true, other arguments are resolved deeply through the shared asset resolver. signalis checked before the chain starts and between operations. Cancellation rejects rather than returning a partial result.concurrencyis accepted by the shared option type for consistency but has no parallelizing effect onchain; chain execution is deliberately sequential.
Return shape contract
Each step must resolve to a Buffer or { buffer: Buffer } such as CanvasResults. Anything else rejects the chain.
Design notes
batchsupports the explicit canvas / image / text operation union. It is not an arbitrary-method dispatcher.chainis the sequential escape hatch for methods such aspath2d.draw, pixel operations, and image operations that consume a previous buffer.- Both surfaces use the central operation-count limits; batch concurrency is bounded by the central runtime configuration.
- Errors preserve the failing operation index and operation type/method through structured Apexify input errors.