developit/workerize

🏗️ Run a module in a Web Worker.

JavaScript

4,375

60 commits

updated Mar 4, 2021

See the code

README

💖 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

threading
web-worker
web-workers

developit/workerize

🏗️ Run a module in a Web Worker.

JavaScript

4,375

60 commits

updated Mar 4, 2021

See the code

README

💖 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

threading
web-worker
web-workers

Project health

Overall

1.6/10

Maintained

0/10

Code review

1/10
OpenSSF Scorecard

Latest release

0.1.8 · Dec 28, 2019

Releases this year

0

Significant stargazers

(top 24 of 42)

Mateusz Burzyński

2,324 followers · starred Jan 2018

Kyle Kelley

1,558 followers · starred Jan 2018

Jon Schlinkert

4,971 followers · starred Jun 2019

Sam Verschueren

822 followers · starred Jan 2018