1.0.1 • Published 3 years ago

worker-dynamic v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

MIT License LinkedIn

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

  1. 构造中opiton对象提供target属性,允许传入方法函数或者js文件链接
  2. worker使用Promise化,多线程异步更加方便

Installation

npm安装

    npm install worker-dynamic --save

Usage

  1. npm包默认导出WorkerDynamic核心类。
  2. 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)
    })  
  3. 若需要传入文件链接,文件中需按照固定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

1.0.1

3 years ago

1.0.0

3 years ago