UNPKG

@minecraft/creator-tools

Version:

Minecraft Creator Tools command line and libraries.

55 lines (54 loc) 2.47 kB
/** * WorkerPool - Abstraction for parallel task execution * * This module provides: * - IWorkerPool interface (from ICommandContext) * - ThreadWorkerPool: Node.js worker_threads implementation * - SingleThreadPool: Executes tasks via worker but one at a time * * Both pools use the same TaskWorker.js script for execution, * ensuring consistent behavior between single and multi-threaded modes. * * The factory function createWorkerPool() selects the appropriate * implementation based on thread count. */ import { IWorkerPool, IWorkerTask, IWorkerResult } from "./ICommandContext"; /** * SingleThreadPool executes tasks one at a time using a single worker. * This provides consistent behavior with ThreadWorkerPool but without parallelism. */ export declare class SingleThreadPool implements IWorkerPool { readonly concurrency = 1; private workerPath; private memoryLimitMb; constructor(workerPath?: string, memoryLimitMb?: number); execute<TArgs, TResult>(task: IWorkerTask<TArgs, TResult>): Promise<IWorkerResult<TResult>>; executeBatch<TArgs, TResult>(tasks: IWorkerTask<TArgs, TResult>[], onProgress?: (completed: number, total: number) => void): Promise<IWorkerResult<TResult>[]>; shutdown(): Promise<void>; } /** * ThreadWorkerPool uses Node.js worker_threads for parallel execution. */ export declare class ThreadWorkerPool implements IWorkerPool { readonly concurrency: number; private workerPath; private memoryLimitMb; private activeWorkers; private isShutdown; /** * Create a thread worker pool. * @param concurrency Maximum concurrent workers * @param workerPath Path to the worker script (TaskWorker.js) * @param memoryLimitMb Memory limit per worker in MB */ constructor(concurrency: number, workerPath?: string, memoryLimitMb?: number); execute<TArgs, TResult>(task: IWorkerTask<TArgs, TResult>): Promise<IWorkerResult<TResult>>; executeBatch<TArgs, TResult>(tasks: IWorkerTask<TArgs, TResult>[], onProgress?: (completed: number, total: number) => void): Promise<IWorkerResult<TResult>[]>; shutdown(): Promise<void>; } /** * Factory function to create the appropriate worker pool. * @param threads Number of threads (1 = single-threaded, >1 = multi-threaded) * @param workerPath Optional path to worker script (defaults to TaskWorker.js) */ export declare function createWorkerPool(threads: number, workerPath?: string): IWorkerPool;