Offload tasks to a pool of workers on node.js and in the browser
Overall
score
95%
Build a configurable pool manager for processing image data in parallel. The system should create worker pools with specific configurations and retrieve information about pool state.
Create a module that provides functionality for managing worker pools with different configurations:
Create a worker pool with specific configuration options:
Retrieve pool statistics including:
Properly terminate the pool when processing is complete
@generates
/**
* Creates and configures a worker pool
*
* @param {Object} config - Pool configuration
* @param {number} config.minWorkers - Minimum number of workers
* @param {number} config.maxWorkers - Maximum number of workers
* @param {number} config.maxQueueSize - Maximum queued tasks
* @param {string} config.workerType - Worker type ('auto', 'web', 'process', 'thread')
* @returns {Object} The configured worker pool
*/
function createPool(config) {
// IMPLEMENTATION HERE
}
/**
* Gets current statistics from the pool
*
* @param {Object} pool - The worker pool
* @returns {Object} Statistics including totalWorkers, busyWorkers, idleWorkers, pendingTasks, activeTasks
*/
function getPoolStats(pool) {
// IMPLEMENTATION HERE
}
/**
* Terminates the worker pool
*
* @param {Object} pool - The worker pool to terminate
* @param {boolean} force - Whether to force immediate termination
* @returns {Promise} Resolves when pool is terminated
*/
function terminatePool(pool, force = false) {
// IMPLEMENTATION HERE
}
module.exports = {
createPool,
getPoolStats,
terminatePool
};Provides worker pool functionality for parallel task processing.
Install with Tessl CLI
npx tessl i tessl/npm-workerpoolevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10