Skip to content

Repository files navigation

TinyWorker

Simplifying the use of Web Workers — call worker functions like regular async functions

✅ Key Features:

  • 🔁 Seamless two-way communication
  • 🧠 Clean, developer-friendly API
  • ⚡ Ideal for offloading heavy computations
  • 🛠️ Supports passing arguments and receiving results like local function calls

Installation

npm install @tinyhref/tiny-worker
or
yarn add @tinyhref/tiny-worker

Use It

import{TinyWorker}from'@tinyhref/tiny-worker';constworker=TinyWorker.init({methods: {counter: 0,inc(){return++this.counter;},add(a: number,b: number){returna+b;},multiply: function(a: number,b: number){console.log('lodash',this._);returna*b;}},imports: ['https://unpkg.com/lodash@4.17.21/lodash.js']});constchannelSharedWorker=TinyWorker.createWorker('channel',{isSharedWorker: true,workerType: 'module',methods: {multiply: async(a: number,b: number)=>{console.log('lodash',lodash)returna*b;}},imports: {'lodash': 'https://esm.sh/lodash-es@4.17.21'}});(async()=>{console.log('1 + 1 = ',awaitworker.add(1,1));console.log('2 * 2 = ',awaitworker.multiply(2,2));})();

About

Simplify Web Worker usage.

Topics

Resources

Stars

48 stars

Watchers

2 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages