workerize

?️ Run a module in a Web Worker.

Github stars Tracking Chart

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

Main metrics

Overview
Name With Ownerdevelopit/workerize
Primary LanguageJavaScript
Program languageJavaScript (Language Count: 2)
Platform
License:
所有者活动
Created At2018-01-09 21:59:27
Pushed At2021-03-04 23:04:53
Last Commit At2019-12-27 20:13:13
Release Count8
Last Release Name0.1.8 (Posted on )
First Release Name0.1.1 (Posted on )
用户参与
Stargazers Count4.4k
Watchers Count50
Fork Count91
Commits Count60
Has Issues Enabled
Issues Count25
Issue Open Count13
Pull Requests Count10
Pull Requests Open Count6
Pull Requests Close Count1
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private