# @matrixai/workers

> Multithreaded Workers

Latest version **2.0.1** (published 2025-04-30) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @matrixai/workers
pnpm add @matrixai/workers
yarn add @matrixai/workers
bun add @matrixai/workers
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2025-04-30 |
| First published | 2021-09-14 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 4 |
| Unpacked size | 67.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Roger Qiu |
| Maintainers | brianbotha74, cmcdragonkai, matrixai-bot |

## Links

- npm: https://www.npmjs.com/package/@matrixai/workers
- Repository: https://github.com/MatrixAI/js-workers
- Homepage: https://github.com/MatrixAI/js-workers#readme
- Issues: https://github.com/MatrixAI/js-workers/issues
- npm.io page: https://npm.io/package/@matrixai/workers

## Dependencies (4)

- [rxjs](https://npm.io/package/rxjs.md) ^7.8.2
- [@matrixai/errors](https://npm.io/package/@matrixai/errors.md) ^2.1.3
- [@matrixai/logger](https://npm.io/package/@matrixai/logger.md) ^4.0.3
- [@matrixai/async-init](https://npm.io/package/@matrixai/async-init.md) ^2.1.2

## Recent versions

- 2.0.1 (latest) — 2025-04-30
- 2.0.0 — 2025-03-11
- 1.4.1 — 2025-02-04
- 1.4.0 — 2023-09-13
- 1.3.7 — 2023-06-23
- 1.3.6 — 2022-07-25
- 1.3.5 — 2022-07-22
- 1.3.4 — 2022-07-22
- 1.3.3 — 2022-05-12
- 1.3.2 — 2022-05-10
- 1.3.1 — 2022-04-11
- 1.3.0 — 2022-04-05
- 1.2.5 — 2021-12-31
- 1.2.4 — 2021-12-29
- 1.2.3 — 2021-09-18
- … 8 more at https://npm.io/package/@matrixai/workers/versions

## README

# js-workers

Workers is the library for multi-threading in MatrixAI's JavaScript/TypeScript applications. It is based on top of threads.js.

Currently no support for Mobile OSes.

Note that only `ArrayBuffer` can be zero-copy transferred to the worker threads. This means if you are wroking with Node `Buffer` you must first slice and copy the `ArrayBuffer` out of the Node `Buffer`.

```ts
const b = Buffer.from('hello world');
const ab = b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength);
```

The following diagram is an example architecture of using `ArrayBuffer`:

```
┌───────────────────────┐
│      Main Thread      │
│                       │
│     ┌───────────┐     │
│     │Node Buffer│     │
│     └─────┬─────┘     │          ┌────────────────────────┐
│           │           │          │                        │
│     Slice │ Copy      │          │      Worker Thread     │
│           │           │          │                        │
│  ┌────────▼────────┐  │ Transfer │  ┌──────────────────┐  │
│  │Input ArrayBuffer├──┼──────────┼──►                  │  │
│  └─────────────────┘  │          │  └─────────┬────────┘  │
│                       │          │            │           │
│                       │          │    Compute │           │
│                       │          │            │           │
│  ┌─────────────────┐  │          │  ┌─────────▼────────┐  │
│  │                 ◄──┼──────────┼──┤Output ArrayBuffer│  │
│  └─────────────────┘  │ Transfer │  └──────────────────┘  │
│                       │          │                        │
│                       │          │                        │
└───────────────────────┘          └────────────────────────┘
```

See the benchmarks and tests for examples of using this library.

## Installation

```sh
npm install --save @matrixai/workers
```

## Development

Run `nix develop`, and once you're inside, you can use:

```sh
# install (or reinstall packages from package.json)
npm install
# build the dist
npm run build
# run the repl (this allows you to import from ./src)
npm run tsx
# run the tests
npm run test
# lint the source code
npm run lint
# automatically fix the source
npm run lintfix
```

## Benchmarks

```sh
npm run bench
```

View benchmarks here: https://github.com/MatrixAI/js-workers/blob/master/benches/results/WorkerManager.chart.html with https://raw.githack.com/

### Docs Generation

```sh
npm run docs
```

See the docs at: https://matrixai.github.io/js-workers/

### Publishing

Publishing is handled automatically by the staging pipeline.

Prerelease:

```sh
# npm login
npm version prepatch --preid alpha # premajor/preminor/prepatch
git push --follow-tags
```

Release:

```sh
# npm login
npm version patch # major/minor/patch
git push --follow-tags
```

Manually:

```sh
# npm login
npm version patch # major/minor/patch
npm run build
npm publish --access public
git push
git push --tags
```

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