worker-dynamic
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i worker-dynamic

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

11.2 kB

Total Files

11

Last publish

Collaborators

  • sumerliu