@dumpstate/web-worker-proxy
TypeScript icon, indicating that this package has built-in type declarations

0.1.8 • Public • Published

web-worker-proxy

Web worker proxy for JavaScript objects.

Installation

Install package:

npm install @dumpstate/web-worker-proxy --save

Usage

  1. Define and build Worker script.
import { run } from "@dumpstate/web-worker-proxy"
import { Foo } from "..."

run(async () => {
	// NB construct an object to be 'run' on the Worker.
	//    e.g. load WASM file.
	return new Foo()
})

Use your favourite build tool, to bundle the script.

  1. Create worker proxy.
import { ProxyType, workerProxy } from "@dumpstate/web-worker-proxy"
import { Foo } from "..."

const foo: ProxyType<Foo> = await workerProxy<Foo>("/path/to/worker/script.js")

// NB ProxyType<Foo> is a type mapping, that for all:
//    - properties, turn them into `() => Promise<T>` functions,
//    - functions, turn them into `(...args) => Promise<ReturnType<T>>` async functions.

foo is a Proxy, that sends a message to a dedicated Worker and resolves appropriate response.

Readme

Keywords

none

Package Sidebar

Install

npm i @dumpstate/web-worker-proxy

Weekly Downloads

1

Version

0.1.8

License

MIT

Unpacked Size

23.9 kB

Total Files

23

Last publish

Collaborators

  • dumpstate