# thread-it

> wrap any sync module to thread worker

Latest version **3.0.0** (published 2025-04-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install thread-it
pnpm add thread-it
yarn add thread-it
bun add thread-it
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2025-04-24 |
| First published | 2019-08-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=16 |
| Dependencies | 3 |
| Unpacked size | 9.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | coderaiser |
| Maintainers | coderaiser |
| Keywords | worker, threads, worker_threads, promise |

## Links

- npm: https://www.npmjs.com/package/thread-it
- Repository: https://github.com/coderaiser/node-thread-it
- Homepage: http://github.com/coderaiser/node-thread-it
- Issues: https://github.com/coderaiser/node-thread-it/issues
- npm.io page: https://npm.io/package/thread-it

## Dependencies (3)

- [try-catch](https://npm.io/package/try-catch.md) ^3.0.1
- [@iocmd/wait](https://npm.io/package/@iocmd/wait.md) ^2.1.0
- [try-to-catch](https://npm.io/package/try-to-catch.md) ^3.0.0

## Alternatives

- [cron](https://npm.io/package/cron.md) — 4.9M weekly downloads
- [@vercel/queue](https://npm.io/package/@vercel/queue.md) — 731.6K weekly downloads
- [create-sonicjs](https://npm.io/package/create-sonicjs.md) — 1.6K weekly downloads
- [@exellix/jobs-api](https://npm.io/package/@exellix/jobs-api.md) — 941 weekly downloads
- [@forwardimpact/libskill](https://npm.io/package/@forwardimpact/libskill.md) — 575 weekly downloads

## Recent versions

- 3.0.0 (latest) — 2025-04-24
- 2.0.0 — 2022-06-11
- 1.1.3 — 2020-02-25
- 1.1.2 — 2019-08-23
- 1.1.1 — 2019-08-23
- 1.1.0 — 2019-08-16
- 1.0.3 — 2019-08-16
- 1.0.2 — 2019-08-16
- 1.0.1 — 2019-08-16
- 1.0.0 — 2019-08-16

## README

# Thread It [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![Coverage Status][CoverageIMGURL]][CoverageURL]

Drastically simplified [worker threads](https://nodejs.org/dist/latest-v12.x/docs/api/worker_threads.html), on node `v8` or `v10` without `--experimental-worker` just
wraps your code with a promise so you don't have to warry about a thing, just use `thread it` and it will use `workers` where can.

Choose any sync module from `npm` and instead of `require` use `threadIt`.

*Caution: not all data types can be passed to Worker Thread, for example you just can't pass a function, read carefully [what types are supported](https://nodejs.org/dist/latest-v12.x/docs/api/worker_threads.html#worker_threads_port_postmessage_value_transferlist).*

## Install

`npm i thread-it`

## API

### threadIt(name[, options])

Under the hood `threadId` uses [holdUp](https://github.com/coderaiser/hold-up) so you can use the same options to find a free worker from queue.

- `name` - string
- `options` - options may contain:
  - `log`
  - `count`
  - `time`

Also you can set `THREAD_IT_COUNT` env variable to workers count, if `0` it means disabled worker threads.

```js
const threadIt = require('thread-it');

// init workers, depend on os.cpus()
threadIt.init();

const putout = threadIt('putout');
const result = await putout(`const t = 'hello'`);

// when you need to override options use
threadIt('putout', {
    count: 5, // default
    time: 1000, // default
    log: () => {}, // default
});

// terminate workers when no need anymore
threadIt.terminate();
```

## Related

- [hold-up](https://github.com/iocmd/hold-up "Hold Up") - setInterval with promises, counter and error handling
- [currify](https://github.com/coderaiser/currify "currify") - translate the evaluation of a function that takes multiple arguments into evaluating a sequence of functions, each with a single or more arguments.
- [fullstore](https://github.com/coderaiser/fullstore "fullstore") - functional variables.
- [wraptile](https://github.com/coderaiser/wraptile "wraptile") - translate the evaluation of a function that takes multiple arguments into evaluating a sequence of 2 functions, each with a any count of arguments.

## License

MIT

[NPMIMGURL]: https://img.shields.io/npm/v/thread-it.svg?style=flat
[BuildStatusIMGURL]: https://travis-ci.com/coderaiser/node-thread-it.svg?branch=master
[LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat
[NPMURL]: https://npmjs.org/package/thread-it "npm"
[BuildStatusURL]: https://travis-ci.com/coderaiser/node-thread-it "Build Status"
[LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License"
[CoverageURL]: https://coveralls.io/github/coderaiser/node-thread-it?branch=master
[CoverageIMGURL]: https://coveralls.io/repos/coderaiser/node-thread-it/badge.svg?branch=master&service=github

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