Offload tasks to a pool of workers on node.js and in the browser
Overall
score
95%
Build a data processing utility that offloads CPU-intensive operations to worker threads. The utility should handle multiple types of data transformations efficiently using a worker pool.
[1, 2, 3, 4, 5], the processNumbers function returns [2, 4, 6, 8, 10] (each number doubled) @test[], the processNumbers function returns [] @test"hello world", the processText function returns "HELLO WORLD" (uppercase transformation) @test"", the processText function returns "" @test@generates
/**
* Processes an array of numbers by doubling each value.
* Offloads the computation to worker threads.
*
* @param {number[]} numbers - Array of numbers to process
* @returns {Promise<number[]>} Promise resolving to array of doubled numbers
*/
async function processNumbers(numbers) {
// IMPLEMENTATION HERE
}
/**
* Processes a text string by converting it to uppercase.
* Offloads the computation to worker threads.
*
* @param {string} text - Text to process
* @returns {Promise<string>} Promise resolving to uppercase text
*/
async function processText(text) {
// IMPLEMENTATION HERE
}
/**
* Releases all worker pool resources.
*
* @returns {Promise<void>} Promise that resolves when cleanup is complete
*/
async function cleanup() {
// IMPLEMENTATION HERE
}
module.exports = {
processNumbers,
processText,
cleanup
};Provides worker pool management for offloading computational tasks.
@satisfied-by
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