Socket
Socket
Sign inDemoInstall

workerize

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    workerize

Run a module in a Web Worker.


Version published
Weekly downloads
2.8K
decreased by-5.55%
Maintainers
1
Install size
27.8 kB
Created
Weekly downloads
 

Readme

Source

💖 Using Webpack? You want workerize-loader ➡️

workerize

Workerize npm travis

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

npm install --save workerize

Usage

Pass either a function or a string containing code.

worker.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 © Jason Miller

Keywords

FAQs

Last updated on 28 Dec 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc