# @labset/task-pool-executor

> task pool executor

Latest version **2.3.0** (published 2023-05-28) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @labset/task-pool-executor
pnpm add @labset/task-pool-executor
yarn add @labset/task-pool-executor
bun add @labset/task-pool-executor
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.3.0 |
| Published | 2023-05-28 |
| First published | 2023-05-28 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 32.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Hasnae R. |
| Maintainers | viqueen |
| Keywords | task, pool, executor |

## Links

- npm: https://www.npmjs.com/package/@labset/task-pool-executor
- Repository: https://github.com/viqueen/task-pool-executor
- Homepage: https://github.com/viqueen/task-pool-executor#readme
- Issues: https://github.com/viqueen/task-pool-executor/issues
- npm.io page: https://npm.io/package/@labset/task-pool-executor

## Dependencies (2)

- [ansi-colors](https://npm.io/package/ansi-colors.md) ^4.1.3
- [cli-progress](https://npm.io/package/cli-progress.md) ^3.11.2

## Recent versions

- 2.3.0 (latest) — 2023-05-28

## README

## task-pool-executor

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=viqueen_task-pool-executor&metric=alert_status)](https://sonarcloud.io/dashboard?id=viqueen_task-pool-executor)
[![Known Vulnerabilities](https://snyk.io/test/github/viqueen/task-pool-executor/badge.svg?targetFile=package.json)](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<string>({ 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<string>();

const delayedTask = (millis: number, title: string) => {
  const run = (ctx?: CliProgressRunContext) =>
    new Promise<string>((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);
```

![cli progress example](./docs/cli-progress-example.png)

---
_Source: https://npm.io/package/@labset/task-pool-executor · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
