Skip to content
Apexify.jsDocs
Apexify.js version v5.4.5

Node / Raster Batch Output · guide

Batch & chain

Current Apexify.js 6.0.0 documentation for Batch & chain.

apexify.jsRuntime: nodeCURRENTSince 6.0.0

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?)

SOURCEtypescript
typescript
Studio
await painter.batch(  operations: BatchOperation[],  opts?: BatchChainAssetOpts): Promise<Buffer[]>;
FieldMeaning
operationsNon-empty array of { type, config }, bounded by the configured batch-operation resource limit.
opts.resolveAssetRefsWhen 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.concurrencyOptional positive integer. The effective value may not exceed the runtime maxBatchConcurrency limit. When omitted, Apexify uses that configured limit.
opts.signalOptional AbortSignal. A pre-aborted signal rejects immediately; aborting during a batch stops scheduling additional work and rejects the batch.

Operation types

typeBehaviour
canvasawait painter.createCanvas(config) → returns canvasResult.buffer.
imageBuilds a temporary 800×600 canvas, then calls createImage(config, baseCanvas).
textUses the same temporary-canvas pattern with createText(config, baseCanvas).
SOURCEtypescript
typescript
Studio
const controller = new AbortController(); const [badge, label] = await painter.batch(  [    { type: 'canvas', config: { width: 120, height: 40, color: '#0f172a' } },    {      type: 'text',      config: [{ text: 'Hi', x: 12, y: 26, font: { size: 18, family: 'Arial' } }],    },  ],  {    resolveAssetRefs: true,    concurrency: 2,    signal: controller.signal,  });

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?)

SOURCEtypescript
typescript
Studio
await painter.chain(  operations: ChainOperation[],  opts?: BatchChainAssetOpts): Promise<Buffer>;

Each step is { method: string; args: unknown[] }.

methodResolution
Top-level namepainter[method] and it must be a function.
Dotted path, e.g. path2d.drawWalks painter properties, so facet methods are supported.

Args, asset resolution, and cancellation

  • 'current' or { __isCurrentBuffer: true } is replaced by the currentBuffer from the previous successful step. On the first step it is undefined unless you pass a real buffer yourself.
  • With resolveAssetRefs: true, other arguments are resolved deeply through the shared asset resolver.
  • signal is checked before the chain starts and between operations. Cancellation rejects rather than returning a partial result.
  • concurrency is accepted by the shared option type for consistency but has no parallelizing effect on chain; 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.

SOURCEtypescript
typescript
Studio
const ribbon = await painter.chain([  { method: 'createCanvas', args: [{ width: 400, height: 80, color: '#111827' }] },  {    method: 'path2d.draw',    args: [      'current',      [        { type: 'moveTo', x: 20, y: 40 },        { type: 'lineTo', x: 380, y: 40 },      ],      { stroke: { color: '#f472b6', width: 4 } },    ],  },]);

Design notes

  • batch supports the explicit canvas / image / text operation union. It is not an arbitrary-method dispatcher.
  • chain is the sequential escape hatch for methods such as path2d.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.

Next steps