sumerliu / worker-dynamic

running js function in worker dynamic

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MIT License LinkedIn


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

  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

About

running js function in worker dynamic

License:MIT License


Languages

Language:TypeScript 100.0%