Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/developit/workerize
🏗️ Run a module in a Web Worker.
https://github.com/developit/workerize
threading web-worker web-workers
Last synced: about 10 hours ago
JSON representation
🏗️ Run a module in a Web Worker.
- Host: GitHub
- URL: https://github.com/developit/workerize
- Owner: developit
- Created: 2018-01-09T21:59:27.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-03-04T23:04:53.000Z (almost 4 years ago)
- Last Synced: 2025-02-15T12:13:49.557Z (5 days ago)
- Topics: threading, web-worker, web-workers
- Language: JavaScript
- Homepage: https://github.com/developit/workerize-loader
- Size: 62.5 KB
- Stars: 4,376
- Watchers: 51
- Forks: 91
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-list - workerize
README
💖 Using Webpack? You want workerize-loader ➡️
# Workerize [](https://www.npmjs.org/package/workerize) [](https://travis-ci.org/developit/workerize)
> Moves a module into a Web Worker, automatically reflecting exported functions as asynchronous proxies.
- Bundles a tiny, purpose-built RPC implementation into your app
- If exported module methods are already async, signature is unchanged
- Supports synchronous and asynchronous worker functions
- Works beautifully with async/await
- Just **800 bytes** of gzipped ES3## Install
```sh
npm install --save workerize
```### Usage
Pass either a function or a string containing code.
**worker.js**:
```js
let worker = workerize(`
export function add(a, b) {
// block for half a second to demonstrate asynchronicity
let start = Date.now();
while (Date.now()-start < 500);
return a + b;
}
`);(async () => {
console.log('3 + 9 = ', await worker.add(3, 9));
console.log('1 + 2 = ', await worker.add(1, 2));
})();
```### License
[MIT License](https://oss.ninja/mit/developit/) © [Jason Miller](https://jasonformat.com)