https://github.com/blackaslight/thread
A wrapper API around the Web Worker API
https://github.com/blackaslight/thread
browser deno javascript typescript webworker
Last synced: 12 months ago
JSON representation
A wrapper API around the Web Worker API
- Host: GitHub
- URL: https://github.com/blackaslight/thread
- Owner: BlackAsLight
- License: mit
- Created: 2025-06-09T10:15:05.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-20T05:55:02.000Z (about 1 year ago)
- Last Synced: 2025-06-20T06:34:26.544Z (about 1 year ago)
- Topics: browser, deno, javascript, typescript, webworker
- Language: TypeScript
- Homepage: https://jsr.io/@doctor/thread
- Size: 7.81 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Thread
Thread is a small module that wraps around the Web Worker API to offer a more
promise like experience to pass values to and receive values from web workers.
## Example main.ts
```ts ignore
import { assertEquals } from "jsr:@std/assert";
import { Thread } from "jsr:@doctor/thread";
const thread = new Thread<[number[], number]>(
new URL("./worker.ts", import.meta.url).href,
);
assertEquals(await thread.send([1, 2, 3]), 6);
thread.terminate();
```
## Example worker.ts
```ts ignore
import { listen } from "jsr:@doctor/thread/worker";
listen<[number[], number]>(function (input) {
return [input.reduce((x, y) => x + y)];
});
```