Skip to content

👷 A simple shorthand to use Node worker_threads with Typescript.

Notifications You must be signed in to change notification settings

viniciusestevam/ts-worker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

👷 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

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

Instantiating a Worker

import { Worker } from 'worker_threads'; // Just for typechecking
import TSWorker from 'ts-worker';

const worker: Worker = TSWorker('worker.ts', {
  workerData: {
    foo: 'bar'
  }
});

worker.on('message', msg => console.log(msg));

About

👷 A simple shorthand to use Node worker_threads with Typescript.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages