0.1.8 • Published 11 months ago

@dumpstate/web-worker-proxy v0.1.8

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

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.

0.1.8

11 months ago

0.1.7

1 year ago

0.1.0

2 years ago