@palasimi/workers
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

palasimi-workers

Promise-based request-response API for dedicated web workers.

Installation

npm i @palasimi/workers

Usage

// worker.ts, compiles to /dist/worker.js
import { initServer } from "@palasimi/workers";

initServer({
  ping: () => "pong",
  pong: () => "ping",
  add: (xs) => xs.reduce((x, y) => x + y),
});

// index.ts
import { initClient } from "@palasimi/workers";

const worker = new Worker("/dist/worker.js");
const call = initClient(worker);

call({ name: "ping" }).then(console.log);
// {id: 1, name: 'ping', value: 'pong', status: 2}

call({ name: "pong" }).then(console.log);
// {id: 2, name: 'pong', value: 'ping', status: 2}

call({ name: "add", value: [1, 2, 3, 4, 5] }).then(console.log);
// {id: 3, name: 'add', value: 15, status: 2}

License

MIT

Package Sidebar

Install

npm i @palasimi/workers

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

9.96 kB

Total Files

7

Last publish

Collaborators

  • lggruspe