{"name":"thread-it","version":"3.0.0","type":"commonjs","author":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com","url":"https://github.com/coderaiser"},"description":"wrap any sync module to thread worker","homepage":"http://github.com/coderaiser/node-thread-it","main":"lib/thread-it.js","repository":{"type":"git","url":"git+https://github.com/coderaiser/node-thread-it.git"},"keywords":["worker","threads","worker_threads","promise"],"scripts":{"test":"madrun test","coverage":"madrun coverage","lint":"madrun lint","fix:lint":"madrun fix:lint","report":"madrun report","watcher":"madrun watcher","watch:test":"madrun watch:test","watch:lint":"madrun watch:lint","watch:tape":"madrun watch:tape","watch:coverage:base":"madrun watch:coverage:base","watch:coverage:tape":"madrun watch:coverage:tape","watch:coverage":"madrun watch:coverage"},"dependencies":{"@iocmd/wait":"^2.1.0","try-catch":"^3.0.1","try-to-catch":"^3.0.0"},"license":"MIT","devDependencies":{"c8":"^10.1.3","coveralls":"^3.0.2","eslint":"^9.25.1","eslint-plugin-n":"^17.17.0","eslint-plugin-node":"^11.0.0","eslint-plugin-putout":"^26.1.0","madrun":"^11.0.1","mock-require":"^3.0.3","nodemon":"^3.1.10","putout":"^40.0.12","supertape":"^11.1.0"},"engines":{"node":">=16"},"publishConfig":{"access":"public"},"_id":"thread-it@3.0.0","gitHead":"17a964a3fe10b6472403da5d97d39d48ed1a9e11","bugs":{"url":"https://github.com/coderaiser/node-thread-it/issues"},"_nodeVersion":"22.14.0","_npmVersion":"11.1.0","dist":{"integrity":"sha512-et0bpCeunAoMQGGswYy5rjNSUA2MuhUCmtBqll988T4u9oMizvjSogzVXKn0Kxv5beBADau9fiQlFh5k6bzlhg==","shasum":"362917d67165b7d0b20202b3e92774ab9ff99f10","tarball":"http://registry-npm.ywwl.com/thread-it/download/thread-it-3.0.0.tgz","fileCount":6,"unpackedSize":10161,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDq4MTf2cbPwK7tTwV48r7AylTv1I9UfssFk4chASncDwIgANIZJdAVkrc5ouItDJ2bhJqdg+v7EEV4zWKdSPCLJIg="}],"size":4019,"noattachment":false,"key":"/thread-it/-/thread-it-3.0.0.tgz"},"_npmUser":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"directories":{},"maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/thread-it_3.0.0_1745504358264_0.7599800472471512"},"_hasShrinkwrap":false,"readme":"# Thread It [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![Coverage Status][CoverageIMGURL]][CoverageURL]\n\nDrastically simplified [worker threads](https://nodejs.org/dist/latest-v12.x/docs/api/worker_threads.html), on node `v8` or `v10` without `--experimental-worker` just\nwraps 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.\n\nChoose any sync module from `npm` and instead of `require` use `threadIt`.\n\n*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).*\n\n## Install\n\n`npm i thread-it`\n\n## API\n\n### threadIt(name[, options])\n\nUnder 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.\n\n- `name` - string\n- `options` - options may contain:\n  - `log`\n  - `count`\n  - `time`\n\nAlso you can set `THREAD_IT_COUNT` env variable to workers count, if `0` it means disabled worker threads.\n\n```js\nconst threadIt = require('thread-it');\n\n// init workers, depend on os.cpus()\nthreadIt.init();\n\nconst putout = threadIt('putout');\nconst result = await putout(`const t = 'hello'`);\n\n// when you need to override options use\nthreadIt('putout', {\n    count: 5, // default\n    time: 1000, // default\n    log: () => {}, // default\n});\n\n// terminate workers when no need anymore\nthreadIt.terminate();\n```\n\n## Related\n\n- [hold-up](https://github.com/iocmd/hold-up \"Hold Up\") - setInterval with promises, counter and error handling\n- [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.\n- [fullstore](https://github.com/coderaiser/fullstore \"fullstore\") - functional variables.\n- [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.\n\n## License\n\nMIT\n\n[NPMIMGURL]: https://img.shields.io/npm/v/thread-it.svg?style=flat\n[BuildStatusIMGURL]: https://travis-ci.com/coderaiser/node-thread-it.svg?branch=master\n[LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat\n[NPMURL]: https://npmjs.org/package/thread-it \"npm\"\n[BuildStatusURL]: https://travis-ci.com/coderaiser/node-thread-it \"Build Status\"\n[LicenseURL]: https://tldrlegal.com/license/mit-license \"MIT License\"\n[CoverageURL]: https://coveralls.io/github/coderaiser/node-thread-it?branch=master\n[CoverageIMGURL]: https://coveralls.io/repos/coderaiser/node-thread-it/badge.svg?branch=master&service=github\n","publish_time":1745504358440,"_cnpm_publish_time":1745504358440,"dist-tags":{"latest":"3.0.0"}}