web-worker-stack
v1.0.0
Published
```typescript // file my-processor.ts
Readme
How to use
// file my-processor.ts
export interface MyProcessor {
doSomeThing(a: string, b: string, c: string): Promise<string[]>
}
export const myProcessor: MyProcessor = {
async doSomeThing(a: string, b: string, c: string) {
console.log("doing");
return [a, b, c];
}
}// file myworker-server.ts
import { myProcessor, MyProcessor } from './my-processor.ts'
import { WorkerServer } from "web-worker-stack/server"
const server = new WorkerServer<MyProcessor>(myProcessor)
server.listen();// file myworker-client.ts
import MyWorker from './myworker-server?worker'
import type { MyProcessor } from './my-processor.ts'
import { WorkerClient } from "web-worker-stack/client"
const worker = new MyWorker()
const client = new WorkerClient<MyProcessor>(worker);
// Use it — `call` returns a Promise, so await it inside an async function
const result = await client.call("doSomeThing", "A", "B", "C")
console.log(result); // ["A", "B", "C"]
