https://github.com/viqueen/task-pool-executor
Provides a simple and a cli progress executor implementations to orchestrate a set of asynchronous tasks
https://github.com/viqueen/task-pool-executor
cli concurrent executor
Last synced: 7 months ago
JSON representation
Provides a simple and a cli progress executor implementations to orchestrate a set of asynchronous tasks
- Host: GitHub
- URL: https://github.com/viqueen/task-pool-executor
- Owner: viqueen
- License: apache-2.0
- Created: 2021-02-24T02:59:23.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2025-07-08T20:44:07.000Z (7 months ago)
- Last Synced: 2025-07-08T21:39:10.715Z (7 months ago)
- Topics: cli, concurrent, executor
- Language: TypeScript
- Homepage:
- Size: 883 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
## task-pool-executor
[](https://sonarcloud.io/dashboard?id=viqueen_task-pool-executor)
[](https://snyk.io/test/github/viqueen/task-pool-executor?targetFile=package.json)
---
Provides a **simple** and a **cli progress** executor implementations to orchestrate a set of
asynchronous tasks
### install it
- **npm**
```bash
npm install @labset/task-pool-executor --save
```
- **yarn**
```bash
yarn add @labset/task-pool-executor
```
### use it
- simple task executor
```typescript
import { taskPoolExecutor } from "@labset/task-pool-executor";
const executor = taskPoolExecutor({ maxConcurrent: 3 });
const task = {
title: "my-task",
run: () => Promise.resolve("done"),
};
executor.submit(task);
await executor.close();
```
- with cli progress support
```typescript
import {
CliProgressRunContext,
cliProgressTaskPoolExecutor,
} from "@labset/task-pool-executor";
const taskPool = cliProgressTaskPoolExecutor();
const delayedTask = (millis: number, title: string) => {
const run = (ctx?: CliProgressRunContext) =>
new Promise((resolve) => {
const interval = setInterval(() => {
ctx?.progress.increment();
}, 8);
const timeout = setTimeout(() => {
clearInterval(interval);
resolve("done");
}, millis);
});
return { title, run };
};
const tasks = new Array(10)
.fill(0)
.map((_v, index) => delayedTask(2000, `task ${index}`));
const internal = async () => {
tasks.forEach((t) => taskPool.submit(t));
await delayedTask(8000, "running").run();
await taskPool.close();
};
internal().then(console.info).catch(console.error);
```
