# @jacoblincool/task

> A mix of eventemitter and promise.

Latest version **1.0.0** (published 2023-01-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install @jacoblincool/task
pnpm add @jacoblincool/task
yarn add @jacoblincool/task
bun add @jacoblincool/task
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-01-29 |
| First published | 2023-01-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 10.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | JacobLinCool |
| Maintainers | jacoblincool |

## Links

- npm: https://www.npmjs.com/package/@jacoblincool/task
- Repository: https://github.com/JacobLinCool/task
- Homepage: https://jacoblincool.github.io/task
- Issues: https://github.com/JacobLinCool/task/issues
- npm.io page: https://npm.io/package/@jacoblincool/task

## Dependencies (1)

- [eventemitter3](https://npm.io/package/eventemitter3.md) ^5.0.0

## Recent versions

- 1.0.0 (latest) — 2023-01-29

## README

# Task

A mix of eventemitter and promise.

## Usage

```ts
import { Task } from "@jacoblincool/task";

main();

async function main() {
    const proc = new Promise<string>((r) => setTimeout(() => r("done"), 10_000));

    const task = new Task(proc, { progress: 0 })
        .on("update", (state) => {
            console.log(state);
        })
        .on("complete", (success, result) => {
            console.log({ success, result });
        });

    (async () => {
        while (true) {
            await new Promise((r) => setTimeout(r, 1000));
            if (task.completed) {
                break;
            }
            task.update((state) => {
                return { progress: state.progress + 1 };
            });
        }
    })();

    await task.complete;
    console.log("All done!");
}
```

Output:

```ts
❯ tsx examples/example.ts
{ progress: 1 }
{ progress: 2 }
{ progress: 3 }
{ progress: 4 }
{ progress: 5 }
{ progress: 6 }
{ progress: 7 }
{ progress: 8 }
{ progress: 9 }
{ success: true, result: 'done' }
All done!
```

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