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
關注者數50
派生數91
提交數60
已啟用問題?
問題數25
打開的問題數13
拉請求數10
打開的拉請求數6
關閉的拉請求數1
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?