Offload tasks to a pool of workers on node.js and in the browser
Overall
score
95%
Build a task execution system that processes computational jobs with configurable time limits to prevent tasks from running indefinitely.
Create a system that can execute computational tasks in parallel workers with the following capabilities:
Your system must handle these specific scenarios:
@generates
/**
* Creates a task processor that executes computational work with timeout limits.
*
* @returns {Object} A task processor with execute and cleanup methods
*/
function createTaskProcessor() {
// IMPLEMENTATION HERE
}
/**
* Executes a task with a specified timeout limit.
*
* @param {Object} processor - The task processor instance
* @param {Function} task - The function to execute (may include a delay parameter)
* @param {number} timeoutMs - Maximum execution time in milliseconds
* @returns {Promise} Resolves with task result or rejects with timeout error
*/
function executeWithTimeout(processor, task, timeoutMs) {
// IMPLEMENTATION HERE
}
/**
* Cleans up resources used by the task processor.
*
* @param {Object} processor - The task processor instance to clean up
* @returns {Promise} Resolves when cleanup is complete
*/
function cleanup(processor) {
// IMPLEMENTATION HERE
}
module.exports = {
createTaskProcessor,
executeWithTimeout,
cleanup
};Provides parallel task execution support.
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