-
Notifications
You must be signed in to change notification settings - Fork 1
Batch
runtoolkit edited this page Apr 13, 2026
·
1 revision
Groups side-effect functions under a named batch. The batch is collected first, then executed atomically on flush.
import { Batch } from './src/batch.js';
const batch = new Batch();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 executingadd() calls begin() automatically if the batch doesn't exist yet.
batch.size('my_batch'); // number of pending functions
batch.list(); // → ['my_batch', ...]Errors thrown inside batched functions are caught and logged to console.error. Remaining functions in the batch continue to execute.