{"ava":{"files":["./test/**/*.test.ts"],"serial":true,"require":["ts-node/register"],"extensions":["ts"],"compileEnhancements":false},"bugs":{"url":"https://github.com/andywer/threads.js/issues"},"dist":{"shasum":"bb67fdea8d24f9997db4097230160d5326addaa5","tarball":"https://registry.npmjs.org/threads/-/threads-1.0.0-beta.2-tsconfig.tgz","fileCount":62,"integrity":"sha512-7F6lckhNtCcdtEQCwTlaAda7dykoymXjjxFkJ0ol5wamVGuphs38TN9Q1309F+GvqjYav3LvP8IVhpBl19aTWQ==","signatures":[{"sig":"MEQCICmg7JXFB0v6NlN8aS8qIEm8IiNyJgPiOxfeVrlFwi00AiBGvyyV5VLQm+yz9AjruXJ6s0vNR5Q5vehvGc+ryiKtWA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":85004,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdKh8cCRA9TVsSAnZWagAA1qUP/337BMMjrz3QsrZTdEoc\ngQZgY5uczPCqfYciBkCa07m2rWpbfzJXzxV1Nm/OsVYBQKWS/6V3/VztOda3\nj/o12+K/2Oq7k83PYrTm5arDR5TvlnYrtwyDfvx57tWIsXsN7rN+1Yb/6dI7\npjicXo6JjE5vnzQ4IVdbxaWHzOFjz6jOEfsRP+Tz/KplgRVympqFkr5N6dBo\nOOrwrxzQwbmX8gy0HPzQyGgrZwZHanRne3gziApBVV6WusqA/Or4zJFWZ5Jk\nwA6AwR8+CN0OEYRVgaGvfrwaL/gsZzIvbGEJ4bUbqf1rsTg/oUfbDEKjyzlK\nnl0eh5cnOvn0ftOEv14GRPycrMeoJxjqPpAOXo6WgLzXHPNQvp9mfNfxvPe7\nc3CFOaUMnM4mi43abMYw74KMul373IpwZzGJclpirZU6TwAlD455M5/AaTA8\nxKV6QTBIIjf7gfLXWA6tvElhRu3Z4ydKjckUE+FYZBdWURVd8h9OAdhAimtw\nh20vyD/b70tVblrqCsRR4+tbzI8JBN/UbqKkybX28F+mwnNrK4P296qbwKxL\n5wvktuRN+1dS+uT/TjbUPDfa9xcouEEsBad++A69L3ChuqKeo1m8tJWzGCXj\nRQX4l31wtZD6GlbkYZXZbnzMyGXVpwhdN3QdcKdcTikTumVmFN0laNOp8NHC\nH8Uk\r\n=ssvv\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/index.js","name":"threads","author":{"url":"https://github.com/andywer","name":"Andy Wermke"},"readme":"<h1 align=\"center\">threads</h1>\n<p align=\"center\">\n  <a href=\"https://travis-ci.org/andywer/threads.js\" target=\"_blank\"><img alt=\"Build status\" src=\"https://img.shields.io/travis/andywer/threads.js/v1.svg?style=flat-square\"></a>\n  <a href=\"https://www.npmjs.com/package/threads\" target=\"_blank\"><img alt=\"npm (tag)\" src=\"https://img.shields.io/npm/v/threads.svg?style=flat-square\"></a>\n</p>\n\nOffload CPU-intensive tasks to worker threads in node.js, web browsers and electron using one uniform API.\n\nUses web workers in the browser, `worker_threads` in node 12+ and [`tiny-worker`](https://github.com/avoidwork/tiny-worker) in node 8 to 11.\n\n### Features\n\n* **Speed up** code by parallel processing\n* **Keep UI responsive** by offloading work from rendering thread\n* First-class support for **async functions** & **observables**\n* Manage bulk task executions with **thread pools**\n* Works great with **webpack**\n\n### Version 0.x\n\nYou can find the old version 0.12 of threads.js on the [`v0` branch](https://github.com/andywer/threads.js/tree/v0). All the content on this page refers to version 1.0 which is a rewrite of the library with a whole new API.\n\n## Installation\n\n```\nnpm install threads tiny-worker\n```\n\n*You only need to install the `tiny-worker` package to support node.js < 12. It's an optional dependency and used as a fallback if `worker_threads` are not available.*\n\n<details>\n<summary>Run on node.js</summary>\n\n<p></p>\n\nRunning code using threads.js in node works out of the box.\n\nNote that we wrap the native `Worker`, so `new Worker(\"./foo/bar\")` will resolve the path relative to the module that calls it, not relative to the current working directory.\n\nThat aligns it with the behavior when bundling the code with webpack or parcel.\n\n</details>\n\n<details>\n<summary>Webpack build setup</summary>\n\n#### Webpack config\n\nUse with the [`threads-plugin`](https://github.com/andywer/threads-plugin). It will transparently detect all `new Worker(\"./unbundled-path\")` expressions, bundles the worker code and replaces the `new Worker(...)` path with the worker bundle path, so you don't need to explicitly use the `worker-loader` or define extra entry points.\n\n```sh\n  npm install -D threads-plugin\n```\n\nThen add it to your `webpack.config.js`:\n\n```diff\n+ const ThreadsPlugin = require('threads-plugin');\n\n  module.exports = {\n    // ...\n    plugins: [\n+     new ThreadsPlugin()\n    ]\n    // ...\n  }\n```\n\n#### Node.js bundles\n\nIf you are using webpack to create a bundle that will be run in node (webpack config `target: \"node\"`), you also need to specify that the `tiny-worker` package used for node < 12 should not be bundled:\n\n```diff\n  module.exports = {\n    // ...\n+   externals: {\n+     \"tiny-worker\": \"tiny-worker\"\n+   }\n    // ...\n}\n```\n\nMake sure that `tiny-worker` is listed in your `package.json` `dependencies` in that case.\n\n#### When using TypeScript\n\nMake sure the TypeScript compiler keeps the `import` / `export` statements intact, so webpack resolves them. Otherwise the `threads-plugin` won't be able to do its job.\n\n```diff\n  module.exports = {\n    // ...\n    module: {\n      rules: [\n        {\n          test: /\\.ts$/,\n          loader: \"ts-loader\",\n+         options: {\n+           compilerOptions: {\n+             module: \"esnext\"\n+           }\n+         }\n        }\n      ]\n    },\n    // ...\n  }\n```\n\n</details>\n\n<details>\n<summary>Parcel bundler setup</summary>\n\n<p></p>\n\nYou need to import `threads/register` once at the beginning of your application code (in the master code, not in the workers):\n\n```diff\n  import { spawn } from \"threads\"\n+ import \"threads/register\"\n\n  // ...\n\n  const work = await spawn(new Worker(\"./worker\"))\n```\n\nThis registers the library's `Worker` implementation for your platform as the global `Worker`. This is necessary, since you cannot `import { Worker } from \"threads\"` or Parcel won't recognize `new Worker()` as a web worker anymore.\n\nBe aware that this might affect any code that tries to instantiate a normal web worker `Worker` and now instead instantiates a threads.js `Worker`. The threads.js `Worker` is just a web worker with some sugar on top, but that sugar might have unexpected side effects on third-party libraries.\n\nEverything else should work out of the box.\n\n</details>\n\n## Getting Started\n\n### Basics\n\n```js\n// master.js\nimport { spawn, Thread, Worker } from \"threads\"\n\nasync function main() {\n  const add = await spawn(new Worker(\"./workers/add\"))\n  const sum = await add(2, 3)\n\n  console.log(`2 + 3 = ${sum}`)\n\n  await Thread.terminate(add)\n}\n\nmain().catch(console.error)\n```\n\n```js\n// workers/add.js\nimport { expose } from \"threads/worker\"\n\nexpose(function add(a, b) {\n  return a + b\n})\n```\n\n### spawn()\n\nThe return value of `add()` in the master code depends on the `add()` return value in the worker:\n\nIf the function returns a promise or an observable then you can just use the return value as such in the master code. If the function returns a primitive value, expect the master function to return a promise resolving to that value.\n\n### expose()\n\nUse `expose()` to make either a function or an object callable from the master thread.\n\nIn case of exposing an object, `spawn()` will asynchronously return an object exposing all the object's functions, following the same rules as functions directly `expose()`-ed.\n\n## Usage\n\n<p>\n  Find the full documentation on the <a href=\"https://threads.js.org/\" rel=\"nofollow\">website</a>:\n</p>\n\n- [**Introduction**](https://threads.js.org/usage#introduction)\n- [**Basics**](https://threads.js.org/usage#basics)\n- [**Observables**](https://threads.js.org/usage#observables)\n- [**Thread pool**](https://threads.js.org/usage#thread-pool)\n- [**Transferable objects**](https://threads.js.org/usage#transferable-objects)\n- [**Thread events**](https://threads.js.org/usage#thread-events)\n\n<!--\n## API\n\nTODO\n-->\n\n## Debug\n\nWe are using the [`debug`](https://github.com/visionmedia/debug) package to provide opt-in debug logging. All the package's debug messages have a scope starting with `threads:`, with different sub-scopes:\n\n- `threads:master:messages`\n- `threads:master:spawn`\n- `threads:master:thread-utils`\n- `threads:pool:${poolName || poolID}`\n\nSet it to `DEBUG=threads:*` to enable all the library's debug logging. To run its tests with full debug logging, for instance:\n\n```\nDEBUG=threads:* npm test\n```\n\n## License\n\nMIT\n","browser":{"ts-node":false,"callsites":false,"tiny-worker":false,"worker_threads":false,"ts-node/register":false,"./dist/master/implementation":"./dist/master/implementation.browser.js","./dist/worker/implementation":"./dist/worker/implementation.browser.js","./dist/master/implementation.node.js":false,"./dist/worker/implementation.tiny-worker.js":false,"./dist/worker/implementation.worker_threads.js":false},"gitHead":"0ac1cc45475929c1c77077ca6b1c9dd0307e2d85","license":"MIT","scripts":{"test":"run-s test:ava test:puppeteer:basic test:puppeteer:webpack","build":"tsc","prepare":"run-s build","pretest":"babel --plugins @babel/plugin-transform-typescript --plugins @babel/plugin-transform-modules-commonjs ./test/workers -d ./test/workers -x .ts","posttest":"tslint --project .","prebuild":"rimraf dist/","test:ava":"cross-env TS_NODE_FILES=true ava","test:puppeteer:basic":"puppet-run plugin:mocha ./test/*.chromium*.ts","test:puppeteer:webpack":"puppet-run --serve ./test/webpack/dist.web/0.worker.js plugin:mocha ./test/webpack/webpack.chromium.mocha.ts"},"_npmUser":{"name":"andywer","email":"andy.dev@next-step-software.com"},"homepage":"https://github.com/andywer/threads.js#readme","keywords":["thread","worker","pool","spawn","isomorphic","parallel","observable","worker_threads"],"repository":{"url":"git+https://github.com/andywer/threads.js.git","type":"git"},"_npmVersion":"6.9.0","description":"Easy to use, yet powerful multi-threading library for node.js, web browsers and Electron","directories":{},"maintainers":[{"name":"andywer","email":"andy@dev.next-step-software.com"}],"_nodeVersion":"10.15.3","dependencies":{"debug":"^4.1.1","callsites":"^3.1.0","tiny-worker":">= 2","is-observable":"^1.1.0","zen-observable":"^0.8.14","@types/zen-observable":"^0.8.0"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"ava":"^1.4.1","chai":"^4.2.0","mocha":"^5.2.0","rimraf":"^2.6.3","tslint":"^5.16.0","ts-node":"^8.1.0","webpack":"^4.32.2","cross-env":"^5.2.0","ts-loader":"^6.0.1","@babel/cli":"^7.4.4","puppet-run":"^0.5.0","typescript":"^3.4.5","@types/chai":"^4.1.7","@types/node":"^11.13.8","npm-run-all":"^4.1.5","tiny-worker":"^2.2.0","@types/debug":"^4.1.4","@types/mocha":"^5.2.6","worker-plugin":"^3.1.0","@types/webpack":"^4.4.32","threads-plugin":"^1.0.0","@types/callsites":"^3.0.0","tslint-config-prettier":"^1.18.0","puppet-run-plugin-mocha":"^0.1.1","@babel/plugin-transform-typescript":"^7.4.4","@babel/plugin-transform-modules-commonjs":"^7.4.4"},"optionalDependencies":{"tiny-worker":">= 2"},"_npmOperationalInternal":{"tmp":"tmp/threads_1.0.0-beta.2-tsconfig_1563041563210_0.9021363265595459","host":"s3://npm-registry-packages"},"_id":"threads@1.0.0-beta.2-tsconfig","version":"1.0.0-beta.2-tsconfig"}