workerize

?️ Run a module in a Web Worker.

Github星跟踪图

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

主要指标

概览
名称与所有者developit/workerize
主编程语言JavaScript
编程语言JavaScript (语言数: 2)
平台
许可证
所有者活动
创建于2018-01-09 21:59:27
推送于2021-03-04 23:04:53
最后一次提交2019-12-27 20:13:13
发布数8
最新版本名称0.1.8 (发布于 )
第一版名称0.1.1 (发布于 )
用户参与
星数4.4k
关注者数48
派生数89
提交数60
已启用问题?
问题数25
打开的问题数13
拉请求数10
打开的拉请求数5
关闭的拉请求数2
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?