Class used to break up work into smaller chunks that are executed asynchronously.

This is often referred to as "batch processing" or "cooperative multitasking," where the time-consuming task is broken into smaller pieces and executed in small intervals to allow the UI to remain responsive.

const batchProcessor = new AcDbBatchProcessing(1000, 10, 50);
await batchProcessor.processChunk(async (start, end) => {
// Process items from start to end
for (let i = start; i < end; i++) {
// Process item i
}
});

Constructors

  • Creates a new AcDbBatchProcessing instance.

    Parameters

    • count: number

      The total number of items to process

    • numerOfChunk: number

      The number of chunks to process

    • minimumChunkSize: number

      The minimum number of items in one chunk. If it is greater than the total number of items to process, the total number is used.

    Returns AcDbBatchProcessing

    const batchProcessor = new AcDbBatchProcessing(1000, 10, 50);
    

Accessors

  • get minimumChunkSize(): number
  • Gets the minimum number of items in one chunk.

    Returns number

    The minimum number of items in one chunk

    const minChunkSize = batchProcessor.minimumChunkSize;
    
  • set minimumChunkSize(value: number): void
  • Sets the minimum number of items in one chunk.

    Parameters

    • value: number

      The new minimum chunk size

    Returns void

    batchProcessor.minimumChunkSize = 100;
    

Methods

  • Processes items in chunks using the provided callback function.

    This method breaks up the work into chunks and processes each chunk asynchronously, allowing the UI to remain responsive.

    Parameters

    • callback: AcDbChunkProcessingCallback

      The callback function to execute for each chunk

    Returns Promise<void>

    Promise that resolves when all chunks have been processed

    await batchProcessor.processChunk(async (start, end) => {
    for (let i = start; i < end; i++) {
    // Process item i
    await processItem(i);
    }
    });