worker-dynamic
Running js function in worker dynamic
View Demo
·
Report Bug
·
Request Feature
Table of Contents
About The Project
Running js function in worker dynamic
version: 1.0.1
lastDate: 2021/3/2
Author: Sumer Liu
Built With
Features
- 构造中opiton对象提供target属性,允许传入方法函数或者js文件链接
- worker使用Promise化,多线程异步更加方便
Installation
npm安装
npm install worker-dynamic --save
Usage
- npm包默认导出WorkerDynamic核心类。
- WorkerDynamic类接受option参数,目前仅支持传入target为worker中执行对象:
import WorkerDynamic from 'worker-dynamic' function test(a){ console.log("param log:", a); return a+1; } const dynamicWorker = new WorkerDynamic({target: test}); dynamicWorker.handler(2).then(res=>{ console.log("worker result : ", res) })
- 若需要传入文件链接,文件中需按照固定onmessage完成result的接受工作
onmessage = function ({data: {jobId, message}}) { ... postMessage({ jobId: jobId, result: result }); ... };
License
Distributed under the MIT License. See LICENSE
for more information.
Contact
Sumer Liu - 843627979@qq.com
Project Link: https://github.com/sumerliu/worker-dynamic