Skip to content
runtoolkit edited this page Apr 13, 2026 · 1 revision

Batch

Groups side-effect functions under a named batch. The batch is collected first, then executed atomically on flush.

Constructor

import { Batch } from './src/batch.js';

const batch = new Batch();

Usage

batch.begin('my_batch');         // start (or reset) a named batch

batch.add('my_batch', () => {    // add a function
  applyDamage(player, 5);
});
batch.add('my_batch', () => {
  sendMessage(player, 'ouch');
});

batch.flush('my_batch');         // execute all, then clear
batch.cancel('my_batch');        // discard without executing

add() calls begin() automatically if the batch doesn't exist yet.


Introspection

batch.size('my_batch');  // number of pending functions
batch.list();            // → ['my_batch', ...]

Error handling

Errors thrown inside batched functions are caught and logged to console.error. Remaining functions in the batch continue to execute.

Clone this wiki locally