taglib-wasm
Version:
TagLib for TypeScript platforms: Deno, Node.js, Bun, Electron, browsers, and Cloudflare Workers
162 lines • 4.15 kB
TypeScript
/**
* @fileoverview Worker pool implementation for parallel audio file processing
*
* Provides efficient parallel processing of audio files using Web Workers,
* with support for both Simple and Full API operations.
*/
import type { AudioProperties, Picture, Tag } from "./types.ts";
/**
* Worker pool configuration options
*/
export interface WorkerPoolOptions {
/** Number of worker threads (defaults to hardwareConcurrency or 4) */
size?: number;
/** Enable debug logging */
debug?: boolean;
/** Worker initialization timeout in ms */
initTimeout?: number;
/** Operation timeout in ms */
operationTimeout?: number;
}
/**
* Task types supported by the worker pool
*/
export type WorkerTask = {
op: "readTags";
file: string | Uint8Array;
} | {
op: "readProperties";
file: string | Uint8Array;
} | {
op: "applyTags";
file: string | Uint8Array;
tags: Partial<Tag>;
} | {
op: "updateTags";
file: string;
tags: Partial<Tag>;
} | {
op: "readPictures";
file: string | Uint8Array;
} | {
op: "setCoverArt";
file: string | Uint8Array;
coverArt: Uint8Array;
mimeType?: string;
} | {
op: "batch";
file: string | Uint8Array;
operations: BatchOperation[];
};
/**
* Batch operations for Full API
*/
export interface BatchOperation {
method: string;
args?: any[];
}
/**
* TagLib Worker Pool for parallel audio file processing
*
* @example
* ```typescript
* // Create a worker pool
* const pool = new TagLibWorkerPool({ size: 4 });
*
* // Process files in parallel
* const tags = await Promise.all(
* files.map(file => pool.readTags(file))
* );
*
* // Batch operations
* const results = await pool.readTagsBatch(files);
*
* // Clean up
* pool.terminate();
* ```
*/
export declare class TagLibWorkerPool {
private workers;
private queue;
private terminated;
private initPromise;
private readonly size;
private readonly debug;
private readonly initTimeout;
private readonly operationTimeout;
constructor(options?: WorkerPoolOptions);
/**
* Wait for the worker pool to be ready
*/
waitForReady(): Promise<void>;
/**
* Initialize worker threads
*/
private initializeWorkers;
/**
* Create a new worker instance
*/
private createWorker;
/**
* Execute a task in the worker pool
*/
private execute;
/**
* Process queued tasks
*/
private processQueue;
/**
* Simple API: Read tags from a file
*/
readTags(file: string | Uint8Array): Promise<Tag>;
/**
* Simple API: Read tags from multiple files
*/
readTagsBatch(files: (string | Uint8Array)[]): Promise<Tag[]>;
/**
* Simple API: Read audio properties
*/
readProperties(file: string | Uint8Array): Promise<AudioProperties | null>;
/**
* Simple API: Apply tags and return modified buffer
*/
applyTags(file: string | Uint8Array, tags: Partial<Tag>): Promise<Uint8Array>;
/**
* Simple API: Update tags on disk
*/
updateTags(file: string, tags: Partial<Tag>): Promise<void>;
/**
* Simple API: Read pictures
*/
readPictures(file: string | Uint8Array): Promise<Picture[]>;
/**
* Simple API: Set cover art
*/
setCoverArt(file: string | Uint8Array, coverArt: Uint8Array, mimeType?: string): Promise<Uint8Array>;
/**
* Full API: Execute batch operations
*/
batchOperations(file: string | Uint8Array, operations: BatchOperation[]): Promise<any>;
/**
* Get current pool statistics
*/
getStats(): {
poolSize: number;
busyWorkers: number;
queueLength: number;
initialized: boolean;
};
/**
* Terminate all workers and clean up resources
*/
terminate(): void;
}
/**
* Get or create a global worker pool instance
*/
export declare function getGlobalWorkerPool(options?: WorkerPoolOptions): TagLibWorkerPool;
/**
* Terminate the global worker pool
*/
export declare function terminateGlobalWorkerPool(): void;
//# sourceMappingURL=worker-pool.d.ts.map