CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-workerpool

Offload tasks to a pool of workers on node.js and in the browser

Overall
score

95%

Overview
Eval results
Files

task.mdevals/scenario-3/

Task Timeout Management System

Build a task execution system that processes computational jobs with configurable time limits to prevent tasks from running indefinitely.

Requirements

Task Processing

Create a system that can execute computational tasks in parallel workers with the following capabilities:

  1. Execute tasks that may take varying amounts of time to complete
  2. Set maximum execution time limits for individual tasks
  3. Automatically stop tasks that exceed their time limits
  4. Handle timeout failures appropriately by returning error information
  5. Continue processing other tasks even when some tasks timeout

Task Scenarios

Your system must handle these specific scenarios:

  • Quick tasks that complete well within their time limit
  • Tasks that approach but don't exceed their time limit
  • Tasks that exceed their time limit and must be stopped
  • Multiple tasks running concurrently with different time limits

Test Cases

  • A task completing in 100ms with a 500ms timeout succeeds and returns the result @test
  • A task taking 800ms with a 300ms timeout fails with a timeout error @test
  • Three tasks with different durations (100ms, 600ms, 100ms) and a 400ms timeout: the first and third succeed while the second times out @test

Implementation

@generates

API

/**
 * 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
};

Dependencies { .dependencies }

workerpool { .dependency }

Provides parallel task execution support.

Install with Tessl CLI

npx tessl i tessl/npm-workerpool

tile.json