项目作者: viniciusestevam

项目描述 :
:construction_worker: A simple shorthand to use Node worker_threads with Typescript.
高级语言: TypeScript
项目地址: git://github.com/viniciusestevam/ts-worker.git
创建时间: 2020-02-17T16:03:39Z
项目社区:https://github.com/viniciusestevam/ts-worker

开源协议:

下载


:construction_worker: ts-worker

A simple shorthand to use Node worker_threads.

For now there is only support for ts-node.

Why?

Typescript still doesn’t offer worker_threads support. To use them, you need to call a .js file to register on ts-node and then from this file call the .ts worker. To decrease verbosity you can use this package.

Usage

  1. npm install ts-worker
  • Import:
    1. import TSWorker from 'ts-worker';

Instantiating a Worker

  1. import { Worker } from 'worker_threads'; // Just for typechecking
  2. import TSWorker from 'ts-worker';
  3. const worker: Worker = TSWorker('worker.ts', {
  4. workerData: {
  5. foo: 'bar'
  6. }
  7. });
  8. worker.on('message', msg => console.log(msg));