{"_id":"workly","_rev":"4127398","name":"workly","description":"A really simple way to move a stand-alone function/class to a web worker.","dist-tags":{"latest":"1.3.1"},"maintainers":[{"name":"shihn","email":""}],"time":{"modified":"2026-03-01T18:25:43.000Z","created":"2018-02-22T22:34:43.186Z","1.3.1":"2020-01-23T21:02:53.937Z","1.3.0":"2019-03-14T19:56:41.996Z","1.2.0":"2019-01-04T23:44:56.927Z","1.0.1":"2018-03-16T15:26:09.389Z","1.0.0":"2018-03-09T07:22:45.753Z","0.1.1":"2018-03-01T23:30:31.379Z","0.0.1":"2018-02-22T22:34:43.186Z"},"users":{},"author":{"name":"Preet Shihn","email":"preetshihn@gmail.com"},"repository":{"type":"git","url":"git+https://github.com/pshihn/workly.git"},"versions":{"1.3.1":{"name":"workly","version":"1.3.1","description":"A really simple way to move a stand-alone function/class to a web worker.","source":"index.js","main":"dist/workly.umd.js","module":"dist/workly.m.js","browser":"dist/workly.js","types":"dist/workly.d.ts","scripts":{"build":"rollup -c","test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/pshihn/workly.git"},"keywords":["worker","webworker"],"author":{"name":"Preet Shihn","email":"preetshihn@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/pshihn/workly/issues"},"homepage":"https://github.com/pshihn/workly#readme","devDependencies":{"rollup":"^1.29.1","rollup-plugin-terser":"^5.2.0"},"gitHead":"ff5071d8a7f1b3d799874b47f17b41b00c194285","_id":"workly@1.3.1","_nodeVersion":"10.16.0","_npmVersion":"6.9.0","dist":{"shasum":"95d34cbac3b47035e56eb7a582a9b24a611393db","size":6155,"noattachment":false,"key":"/workly/-/workly-1.3.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/workly/download/workly-1.3.1.tgz"},"maintainers":[{"name":"shihn","email":""}],"_npmUser":{"name":"shihn","email":"preetshihn@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/workly_1.3.1_1579813373798_0.9014175549540682"},"_hasShrinkwrap":false,"publish_time":1579813373937,"_cnpm_publish_time":1579813373937,"_cnpmcore_publish_time":"2021-12-17T02:50:25.091Z"},"1.3.0":{"name":"workly","version":"1.3.0","description":"A really simple way to move a stand-alone function/class to a web worker.","source":"index.js","main":"dist/workly.umd.js","module":"dist/workly.m.js","browser":"dist/workly.js","types":"dist/workly.d.ts","scripts":{"build":"rollup -c","test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/pshihn/workly.git"},"keywords":["worker","webworker"],"author":{"name":"Preet Shihn","email":"preetshihn@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/pshihn/workly/issues"},"homepage":"https://github.com/pshihn/workly#readme","devDependencies":{"rollup":"^1.6.0","rollup-plugin-terser":"^4.0.4"},"gitHead":"288871a4f26c03287c07502551aacb02af34ad87","_id":"workly@1.3.0","_nodeVersion":"8.11.1","_npmVersion":"6.7.0","dist":{"shasum":"86cd453139732ef1540ed7f094e058a3e879ba43","size":6159,"noattachment":false,"key":"/workly/-/workly-1.3.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/workly/download/workly-1.3.0.tgz"},"maintainers":[{"name":"shihn","email":""}],"_npmUser":{"name":"shihn","email":"preetshihn@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/workly_1.3.0_1552593401853_0.3715337539859924"},"_hasShrinkwrap":false,"publish_time":1552593401996,"_cnpm_publish_time":1552593401996,"_cnpmcore_publish_time":"2021-12-17T02:50:25.416Z"},"1.2.0":{"name":"workly","version":"1.2.0","description":"A really simple way to move a stand-alone function/class to a web worker.","source":"index.js","module":"dist/workly.m.js","main":"dist/workly.js","browser":"dist/workly.js","types":"dist/workly.d.ts","scripts":{"build":"rollup -c","test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/pshihn/workly.git"},"keywords":["worker","webworker"],"author":{"name":"Preet Shihn","email":"preetshihn@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/pshihn/workly/issues"},"homepage":"https://github.com/pshihn/workly#readme","devDependencies":{"rollup":"^1.0.1","rollup-plugin-terser":"^4.0.1"},"gitHead":"c3b77e3df2edb41d474ba63dc82b6ce589654b55","_id":"workly@1.2.0","_npmVersion":"6.4.1","_nodeVersion":"8.11.1","_npmUser":{"name":"shihn","email":"preetshihn@gmail.com"},"dist":{"shasum":"520704a584adc1dcf60bfa20e5a6d90947650bef","size":5816,"noattachment":false,"key":"/workly/-/workly-1.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/workly/download/workly-1.2.0.tgz"},"maintainers":[{"name":"shihn","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/workly_1.2.0_1546645496809_0.3439250118814414"},"_hasShrinkwrap":false,"publish_time":1546645496927,"_cnpm_publish_time":1546645496927,"_cnpmcore_publish_time":"2021-12-17T02:50:25.645Z"},"1.0.1":{"name":"workly","version":"1.0.1","description":"A really simple way to move a stand-alone function/class to a web worker.","main":"dist/workly.umd.js","jsnext:main":"index.js","scripts":{"build":"npm run build-d && npm run build-umd","build-d":"rollup index.js --o dist/workly.js --f iife --name \"workly\" && npm run minify-d","minify-d":"babel-minify dist/workly.js -o dist/workly.min.js --mangle","build-umd":"rollup index.js --o dist/workly.umd.js --f umd --name \"workly\" && npm run minify-umd","minify-umd":"babel-minify dist/workly.umd.js -o dist/workly.umd.min.js --mangle","test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/pshihn/workly.git"},"keywords":["worker","webworker"],"author":{"name":"Preet Shihn","email":"preetshihn@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/pshihn/workly/issues"},"homepage":"https://github.com/pshihn/workly#readme","devDependencies":{"babel-minify":"^0.3.0","rollup":"^0.56.3"},"gitHead":"498af55b96b0c801b8287c3affa910ecdc579c02","_id":"workly@1.0.1","_npmVersion":"5.6.0","_nodeVersion":"8.9.4","_npmUser":{"name":"shihn","email":"preetshihn@gmail.com"},"dist":{"shasum":"ade6d9b8b937c2721ab9bd1b2c93c78131b62dee","size":5827,"noattachment":false,"key":"/workly/-/workly-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/workly/download/workly-1.0.1.tgz"},"maintainers":[{"name":"shihn","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/workly_1.0.1_1521213969354_0.85209929880079"},"_hasShrinkwrap":false,"publish_time":1521213969389,"_cnpm_publish_time":1521213969389,"_cnpmcore_publish_time":"2021-12-17T02:50:25.888Z"},"1.0.0":{"name":"workly","version":"1.0.0","description":"A really simple way to move a stand-alone function/class to a web worker.","main":"index.js","scripts":{"build":"rollup index.js --o dist/workly.js --f iife  --name \"workly\" && npm run minify","minify":"babel-minify --mangle dist/workly.js >> dist/workly.min.js","test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/pshihn/workly.git"},"keywords":["worker","webworker"],"author":{"name":"Preet Shihn","email":"preetshihn@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/pshihn/workly/issues"},"homepage":"https://github.com/pshihn/workly#readme","devDependencies":{"babel-minify":"^0.3.0","rollup":"^0.56.3"},"gitHead":"750278738660c1f800700e12cc326dbb23366d75","_id":"workly@1.0.0","_npmVersion":"5.6.0","_nodeVersion":"8.9.4","_npmUser":{"name":"shihn","email":"preetshihn@gmail.com"},"dist":{"shasum":"bb70d977e06a2c48851d02eb6d0409419f1fead6","size":5406,"noattachment":false,"key":"/workly/-/workly-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/workly/download/workly-1.0.0.tgz"},"maintainers":[{"name":"shihn","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/workly_1.0.0_1520580165699_0.11774813632238113"},"_hasShrinkwrap":false,"publish_time":1520580165753,"_cnpm_publish_time":1520580165753,"_cnpmcore_publish_time":"2021-12-17T02:50:26.108Z"},"0.1.1":{"name":"workly","version":"0.1.1","description":"Simple web worker wrapper using promises (and async/await)","main":"index.js","scripts":{"build":"rollup index.js --o dist/workly.js --f iife  --name \"workly\" && npm run minify","minify":"babel-minify --mangle dist/workly.js >> dist/workly.min.js","test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/pshihn/workly.git"},"keywords":["worker","webworker"],"author":{"name":"Preet Shihn","email":"preetshihn@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/pshihn/workly/issues"},"homepage":"https://github.com/pshihn/workly#readme","devDependencies":{"babel-minify":"^0.3.0","rollup":"^0.56.3"},"gitHead":"9dd60d58cdca27006b51773785ae130779944cd0","_id":"workly@0.1.1","_npmVersion":"5.6.0","_nodeVersion":"8.9.4","_npmUser":{"name":"shihn","email":"preetshihn@gmail.com"},"dist":{"shasum":"7d44075e738ccba5889ea48e3c6b09e06689f45b","size":5291,"noattachment":false,"key":"/workly/-/workly-0.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/workly/download/workly-0.1.1.tgz"},"maintainers":[{"name":"shihn","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/workly_0.1.1_1519947031309_0.5160786382432392"},"_hasShrinkwrap":false,"publish_time":1519947031379,"_cnpm_publish_time":1519947031379,"_cnpmcore_publish_time":"2021-12-17T02:50:26.344Z"},"0.0.1":{"name":"workly","version":"0.0.1","description":"Simple web worker wrapper using promises (and async/await)","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/pshihn/workly.git"},"keywords":["worker","webworker"],"author":{"name":"Preet Shihn","email":"preetshihn@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/pshihn/workly/issues"},"homepage":"https://github.com/pshihn/workly#readme","gitHead":"fac3c0bdca7e1c451f5370ccf916935d46fd1f5e","_id":"workly@0.0.1","_npmVersion":"5.6.0","_nodeVersion":"8.9.4","_npmUser":{"name":"shihn","email":"preetshihn@gmail.com"},"dist":{"shasum":"64b6bfd2df09392a618b4828b8ac0979bfb0e565","size":1114,"noattachment":false,"key":"/workly/-/workly-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/workly/download/workly-0.0.1.tgz"},"maintainers":[{"name":"shihn","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/workly_0.0.1_1519338883127_0.64791305141191"},"_hasShrinkwrap":false,"publish_time":1519338883186,"_cnpm_publish_time":1519338883186,"_cnpmcore_publish_time":"2021-12-17T02:50:26.548Z"}},"readme":"# Workly    ????️‍♀️→ ???? \n\n* A really simple way to move a stand-alone <b>function/class to a worker thread</b>.\n* Or, **expose an object or function in a worker** to the main thread.\n* All calls are made asynchronous. Works great with async/await.\n* Only 1kB gzipped.\n\n## Install\n\nDownload the latest from [dist folder](https://github.com/pshihn/workly/tree/master/dist)\n\nor from npm:\n```\nnpm install --save workly\n```\n\n## Usage\n\nMoving a function to a worker is really simple.\n```js\nfunction busyAdd(a, b) {\n  let st = Date.now();\n  while (true) {\n    if ((Date.now() - st) > 2000) break;\n  }\n  return a + b;\n}\n\n(async () => {\n  let workerAdd = workly.proxy(busyAdd);\n  console.log(await workerAdd(23, 16)); // 39\n  // the busyAdd is executed in a worker so\n  // the UI does not get blocked\n})();\n```\n\nOr, in fact a Class\n\n```js\nclass Adder {\n  constructor() {\n    this.count = 0;\n  }\n  add(a, b) {\n    this.count++;\n    return a + b;\n  }\n}\n\n(async () => {\n  let WAdder = workly.proxy(Adder);\n  let a = await new WAdder(); // instance created/running in worker\n  console.log(await a.count); // 0\n  console.log(await a.add(23, 16)); // 39\n  console.log(await a.count); // 1\n})();\n```\n\n### Custom workers\nThe above examples only work when the class/function is not dependent on the containing scope, i.e. other libraries or global objects. But, you can create a custom worker.js file and move the code in there. In the worker, you can expose your object/function/class using <i>workly.expose</i> method.\n\nIn this example, the function depends on moment.js\n\n<b>worker.js</b>\n```js\nimportScripts('https://cdn.jsdelivr.net/npm/moment@2.20.1/moment.min.js', '../dist/workly.js');\nfunction friendlyTime(value) {\n  return moment(value).calendar(null, {\n    sameDay: function (now) {\n      if (now - this < 1000 * 60) {\n        return \"[Just now]\";\n      } else if (now - this < 1000 * 60 * 60) {\n        return \"[\" + Math.round((now - this) / (1000 * 60)) + \" mins ago]\";\n      } else {\n        return '[Today at] LT'\n      }\n    }\n  });\n}\nworkly.expose(friendlyTime);\n```\n<b>main.js</b>\n```js\n(async () => {\n  let w = workly.proxy(\"./worker.js\");\n  let now = Date.now();\n  console.log(now);\n  console.log(await w(now));\n  console.log(await w(now - (24 * 60 * 60 * 1000)));\n  console.log(await w(now - (4 * 24 * 60 * 60 * 1000)));\n})();\n```\n\n### Caveats\n* If you're not using a custom worker, the function/class being pushed to the worker cannot depend on the containing scope.\n* Since workers do not have access to DOM, DOM manipulation is not supported. \n* Objects passed into functions are not passed by reference, so if the function in the worker updates the passed in object, it will not affect the object in the main scope. \n\n### Examples\nSee the [examples folder](https://github.com/pshihn/workly/tree/master/examples)\n\n### License\n[MIT License](https://github.com/pshihn/workly/blob/master/LICENSE) (c) [Preet Shihn](https://twitter.com/preetster)\n\n### You may also be interested in\n[windtalk](https://github.com/pshihn/windtalk) - Simplest way to communicate between windows or iframes. Work with objects/functions defined in another window or iframe.\n\n","_attachments":{},"homepage":"https://github.com/pshihn/workly#readme","bugs":{"url":"https://github.com/pshihn/workly/issues"},"license":"MIT"}