{"id":19124451,"url":"https://github.com/panates/power-tasks","last_synced_at":"2026-04-01T18:25:19.369Z","repository":{"id":37402277,"uuid":"456111984","full_name":"panates/power-tasks","owner":"panates","description":"Total task management","archived":false,"fork":false,"pushed_at":"2026-03-18T15:24:01.000Z","size":1159,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-03-19T02:48:35.026Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/panates.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":"support/package.cjs.json","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-02-06T09:55:54.000Z","updated_at":"2026-03-18T15:24:11.000Z","dependencies_parsed_at":"2024-06-19T14:34:11.130Z","dependency_job_id":"1fdb08b9-6aac-4b5e-a1af-3f8ca511abb3","html_url":"https://github.com/panates/power-tasks","commit_stats":{"total_commits":81,"total_committers":1,"mean_commits":81.0,"dds":0.0,"last_synced_commit":"872a372b89c4bece4bf7a4ea100c26df87229717"},"previous_names":[],"tags_count":40,"template":false,"template_full_name":null,"purl":"pkg:github/panates/power-tasks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panates%2Fpower-tasks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panates%2Fpower-tasks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panates%2Fpower-tasks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panates%2Fpower-tasks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/panates","download_url":"https://codeload.github.com/panates/power-tasks/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panates%2Fpower-tasks/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31290841,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-01T13:12:26.723Z","status":"ssl_error","status_checked_at":"2026-04-01T13:12:25.102Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T05:29:12.458Z","updated_at":"2026-04-01T18:25:19.290Z","avatar_url":"https://github.com/panates.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# power-tasks\n\n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![CI Tests][ci-test-image]][ci-test-url]\n[![Test Coverage][coveralls-image]][coveralls-url]\n\nPowerful task management for JavaScript/TypeScript. Support for hierarchical tasks, dependencies, concurrency control,\nand a task queue.\n\n## Installation\n\n- `npm install power-tasks --save`\n\n## Node Compatibility\n\n- node `\u003e= 14.x`\n\n## Core Concepts\n\n### Task\n\nA `Task` represents a unit of work that can be executed. It can be a simple function, or it can have children and\ndependencies. Tasks are `AsyncEventEmitter` instances, meaning they emit events during their lifecycle.\n\n#### Creating a Simple Task\n\n```typescript\nimport { Task } from 'power-tasks';\n\nconst task = new Task(async ({signal}) =\u003e {\n  // Do some work\n  return 'Result';\n});\n\ntask.on('start', () =\u003e console.log('Task started!'));\ntask.on('finish', (t) =\u003e console.log(`Task finished with result: ${t.result}`));\n\nawait task.start();\n```\n\n#### Hierarchical Tasks\n\nTasks can have children. A parent task is considered finished when all its children are finished.\n\n```typescript\nconst parent = new Task([\n  new Task(async () =\u003e 'Child 1'),\n  new Task(async () =\u003e 'Child 2')\n], {name: 'Parent Task'});\n\nawait parent.start();\n```\n\n#### Task Dependencies\n\nTasks can depend on other tasks by their name or instance. A task will wait for its dependencies to finish before\nstarting.\n\n```typescript\nconst task1 = new Task(async () =\u003e 'Result 1', {name: 'T1'});\nconst task2 = new Task(async () =\u003e 'Result 2', {\n  name: 'T2',\n  dependencies: ['T1']\n});\n\nconst parent = new Task([task1, task2]);\nawait parent.start();\n```\n\n### TaskQueue\n\n`TaskQueue` manages a list of tasks with concurrency control. It allows you to limit the number of tasks running at the\nsame time and provides methods to pause, resume, and clear the queue.\n\n```typescript\nimport { TaskQueue } from 'power-tasks';\n\nconst queue = new TaskQueue({concurrency: 2});\n\nqueue.enqueue(async () =\u003e { /* ... */\n});\nqueue.enqueue(async () =\u003e { /* ... */\n});\nqueue.enqueue(async () =\u003e { /* ... */\n});\n\nawait queue.wait(); // Wait for all tasks to finish\n```\n\n## API Reference\n\n### Task\n\nA `Task` represents a unit of work that can be executed. It supports hierarchical tasks, dependencies, and emits events\nthroughout its lifecycle.\n\n#### Constructor\n\n- `new Task(execute, options?)`\n    - `execute`: `TaskFunction` - The function to be executed by the task.\n    - `options`: `[TaskOptions](#taskoptions) - Configuration options for the task.\n- `new Task(children, options?)`\n    - `children`: `TaskLike[]` - An array of child tasks or task functions.\n    - `options`: [TaskOptions](#taskoptions) - Configuration options for the task.\n\n#### Properties\n\n| Property             | Type                        | Description                                                                   |\n|----------------------|-----------------------------|-------------------------------------------------------------------------------|\n| `id`                 | `string`                    | Unique identifier of the task.                                                |\n| `name`               | `string` \\| `undefined`     | Name of the task.                                                             |\n| `status`             | [TaskStatus](#taskstatus)   | Current status of the task.                                                   |\n| `message`            | `string`                    | Current message of the task.                                                  |\n| `result`             | `any`                       | Result produced by the task.                                                  |\n| `error`              | `any`                       | Error if the task failed.                                                     |\n| `isFailed`           | `boolean`                   | Whether the task has failed.                                                  |\n| `isAborted`          | `boolean`                   | Whether the task has been aborted or aborting                                 |\n| `isFinished`         | `boolean`                   | Whether the task has completed (successfully, failed, or aborted).            |\n| `isStarted`          | `boolean`                   | Whether the task has started but not yet finished.                            |\n| `executeDuration`    | `number` \\| `undefined`     | Duration of the task execution in milliseconds.                               |\n| `children`           | `Task[]` \\| `undefined`     | List of child tasks.                                                          |\n| `dependencies`       | `Task[]` \\| `undefined`     | List of tasks this task depends on.                                           |\n| `failedChildren`     | `Task[]` \\| `undefined`     | List of child tasks that failed.                                              |\n| `failedDependencies` | `Task[]` \\| `undefined`     | List of dependencies that failed.                                             |\n| `needWaiting`        | `boolean`                   | Whether the task is currently waiting for children or dependencies to finish. |\n| `options`            | [TaskOptions](#taskoptions) | Task configuration options.                                                   |\n| `parent`             | `Task` \\| `undefined`       | The parent task if this is a child task.                                      |\n\n#### Methods\n\n- `start()`: Starts the task execution. Returns the task instance.\n  ```typescript\n  task.start();\n  ```\n- `abort()`: Aborts the task execution. Returns the task instance.\n  ```typescript\n  task.abort();\n  ```\n- `toPromise()`: Returns a promise that resolves with the task result or rejects with the task error.\n  ```typescript\n  const result = await task.toPromise();\n  ```\n- `getWaitingTasks()`: Gets a list of tasks that this task is currently waiting for.\n  ```typescript\n  const waitingTasks = task.getWaitingTasks();\n  ```\n- `reset()`: Resets the task to its initial state so it can be started again.\n  ```typescript\n  task.reset();\n  ```\n- `toJSON()`: Returns a JSON-compatible representation of the task.\n  ```typescript\n  const json = task.toJSON();\n  ```\n\n#### Events\n\n- `start`: Emitted when the task starts.\n  ```typescript\n  task.on('start', (task) =\u003e console.log('Started'));\n  ```\n- `run`: Emitted when the execution function is called.\n  ```typescript\n  task.on('run', (task) =\u003e console.log('Running'));\n  ```\n- `finish`: Emitted when the task finishes (successfully, failed, or aborted).\n  ```typescript\n  task.on('finish', (task) =\u003e console.log('Finished'));\n  ```\n- `abort`: Emitted when the task is aborted.\n  ```typescript\n  task.on('abort', (task) =\u003e console.log('Aborted'));\n  ```\n- `status-change`: Emitted when the task status changes.\n  ```typescript\n  task.on('status-change', (task, status) =\u003e console.log('Status changed to', status));\n  ```\n- `update`: Emitted when task properties are updated.\n  ```typescript\n  task.on('update', (task, properties) =\u003e console.log('Updated', properties));\n  ```\n- `update-recursive`: Emitted when properties of the task or any of its children are updated.\n  ```typescript\n  task.on('update-recursive', (task, properties) =\u003e console.log('Recursive update', properties));\n  ```\n- `error`: Emitted when an error occurs.\n  ```typescript\n  task.on('error', (error, task) =\u003e console.error(error));\n  ```\n- `wait-end`: Emitted when the task stops waiting for dependencies.\n  ```typescript\n  task.on('wait-end', () =\u003e console.log('Wait ended'));\n  ```\n\n### TaskOptions\n\n| Option              | Type                        | Description                                                                                     |\n|---------------------|-----------------------------|-------------------------------------------------------------------------------------------------|\n| `id`                | `any`                       | Unique identifier for the task.                                                                 |\n| `name`              | `string`                    | Name of the task (used for dependencies).                                                       |\n| `args`              | `any[]`                     | Arguments passed to the task function.                                                          |\n| `children`          | `TaskLike[]` \\| `() =\u003e ...` | List of child tasks or a function that returns them.                                            |\n| `dependencies`      | `(Task \\| string)[]`        | Tasks that must finish before this task starts.                                                 |\n| `concurrency`       | `number`                    | Number of child tasks to run in parallel.                                                       |\n| `bail`              | `boolean`                   | If true (default), aborts children if one fails.                                                |\n| `serial`            | `boolean`                   | If true, runs children one by one (shortcut for concurrency: 1).                                |\n| `exclusive`         | `boolean`                   | If true, the task queue waits for this task to complete exclusively.                            |\n| `abortSignal`       | `AbortSignal`               | An optional AbortSignal object that can be used to communicate with, or to abort, an operation. |\n| `abortTimeout`      | `number`                    | Timeout in ms to wait for aborting tasks.                                                       |\n| `onStart`           | `Function`                  | Callback invoked when the task starts.                                                          |\n| `onFinish`          | `Function`                  | Callback invoked when the task finishes.                                                        |\n| `onRun`             | `Function`                  | Callback invoked when the task's execution function begins.                                     |\n| `onStatusChange`    | `Function`                  | Callback invoked when the task's status changes.                                                |\n| `onUpdate`          | `Function`                  | Callback invoked when the task's properties are updated.                                        |\n| `onUpdateRecursive` | `Function`                  | Callback invoked when properties of the task or its children are updated.                       |\n\n### TaskStatus\n\nA task can be in one of the following states:\n\n- `idle`: Task is created but not yet started.\n- `waiting`: Task is waiting for its dependencies.\n- `running`: Task is currently executing.\n- `fulfilled`: Task completed successfully.\n- `failed`: Task failed with an error.\n- `aborting`: Task is in the process of being aborted.\n- `aborted`: Task has been aborted.\n\n### TaskQueue\n\n`TaskQueue` manages the execution of tasks with concurrency control.\n\n#### Constructor\n\n- `new TaskQueue(options?)`\n    - `options`: `TaskQueueOptions` - Configuration options for the queue.\n\n#### Properties\n\n| Property      | Type                    | Description                                                   |\n|---------------|-------------------------|---------------------------------------------------------------|\n| `size`        | `number`                | Total number of tasks in the queue (both queued and running). |\n| `running`     | `number`                | Number of tasks currently running.                            |\n| `queued`      | `number`                | Number of tasks currently waiting in the queue.               |\n| `paused`      | `boolean`               | Whether the queue is currently paused.                        |\n| `concurrency` | `number` \\| `undefined` | The maximum number of tasks to run concurrently.              |\n| `maxQueue`    | `number` \\| `undefined` | The maximum number of tasks allowed in the queue.             |\n\n#### Methods\n\n- `enqueue(task)`: Adds a task to the end of the queue. Returns the `Task` instance.\n  ```typescript\n  const task = queue.enqueue(async () =\u003e 'Done');\n  ```\n- `enqueuePrepend(task)`: Adds a task to the beginning of the queue. Returns the `Task` instance.\n  ```typescript\n  queue.enqueuePrepend(myTask);\n  ```\n- `getTask(id)`: Retrieves a task by its ID. Returns the `Task` instance if found, or `undefined` otherwise.\n  ```typescript\n  const task = queue.getTask('my-task-id');\n  ```\n- `pause()`: Pauses the queue execution.\n  ```typescript\n  queue.pause();\n  ```\n- `resume()`: Resumes the queue execution.\n  ```typescript\n  queue.resume();\n  ```\n- `clearQueue()`: Removes all queued tasks and aborts them.\n  ```typescript\n  queue.clearQueue();\n  ```\n- `abortAll()`: Aborts all running tasks and clears the queue.\n  ```typescript\n  queue.abortAll();\n  ```\n- `wait()`: Returns a promise that resolves when all tasks have finished and the queue is empty.\n  ```typescript\n  await queue.wait();\n  ```\n\n#### Events\n\n- `enqueue`: Emitted when a task is added to the queue.\n  ```typescript\n  queue.on('enqueue', (task) =\u003e console.log('Task enqueued'));\n  ```\n- `finish`: Emitted when all tasks in the queue have finished and the queue is empty.\n  ```typescript\n  queue.on('finish', () =\u003e console.log('Queue finished'));\n  ```\n- `error`: Emitted when a task in the queue emits an error.\n  ```typescript\n  queue.on('error', (error, task) =\u003e console.error(error));\n  ```\n\n### TaskQueueOptions\n\n| Option        | Type      | Description                                                           |\n|---------------|-----------|-----------------------------------------------------------------------|\n| `concurrency` | `number`  | The maximum number of tasks to run concurrently.                      |\n| `maxQueue`    | `number`  | The maximum number of tasks allowed in the queue (including running). |\n| `paused`      | `boolean` | Whether the queue should start in a paused state.                     |\n\n### License\n\n[MIT](LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/power-tasks.svg\n\n[npm-url]: https://npmjs.org/package/power-tasks\n\n[ci-test-image]: https://github.com/panates/power-tasks/actions/workflows/test.yml/badge.svg\n\n[ci-test-url]: https://github.com/panates/power-tasks/actions/workflows/test.yml\n\n[coveralls-image]: https://img.shields.io/coveralls/panates/power-tasks/master.svg\n\n[coveralls-url]: https://coveralls.io/r/panates/power-tasks\n\n[downloads-image]: https://img.shields.io/npm/dm/power-tasks.svg\n\n[downloads-url]: https://npmjs.org/package/power-tasks\n\n[gitter-image]: https://badges.gitter.im/panates/power-tasks.svg\n\n[gitter-url]: https://gitter.im/panates/power-tasks?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge\n\n[dependencies-image]: https://david-dm.org/panates/power-tasks/status.svg\n\n[dependencies-url]:https://david-dm.org/panates/power-tasks\n\n[devdependencies-image]: https://david-dm.org/panates/power-tasks/dev-status.svg\n\n[devdependencies-url]:https://david-dm.org/panates/power-tasks?type=dev\n\n[quality-image]: http://npm.packagequality.com/shield/power-tasks.png\n\n[quality-url]: http://packagequality.com/#?package=power-tasks\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpanates%2Fpower-tasks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpanates%2Fpower-tasks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpanates%2Fpower-tasks/lists"}