Skip to content

Commit

Permalink
Processor can send transferrable objects out
Browse files Browse the repository at this point in the history
  • Loading branch information
DallasHoff committed Aug 6, 2024
1 parent 9ae2131 commit 2ea16db
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export class SQLocalProcessor {

protected proxy: WorkerProxy;

onmessage: ((message: OutputMessage) => void) | undefined;
onmessage:
| ((message: OutputMessage, transfer: Transferable[]) => void)
| undefined;

constructor(worker: typeof globalThis) {
this.proxy = coincident(worker) as WorkerProxy;
Expand Down Expand Up @@ -123,9 +125,12 @@ export class SQLocalProcessor {
await this.initMutex.unlock();
};

protected emitMessage = (message: OutputMessage): void => {
protected emitMessage = (
message: OutputMessage,
transfer: Transferable[] = []
): void => {
if (this.onmessage) {
this.onmessage(message);
this.onmessage(message, transfer);
}
};

Expand Down
9 changes: 7 additions & 2 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@ import { SQLocalProcessor } from './processor.js';

const processor = new SQLocalProcessor(self);

self.onmessage = (message) => processor.postMessage(message);
processor.onmessage = (message) => self.postMessage(message);
self.onmessage = (message) => {
processor.postMessage(message);
};

processor.onmessage = (message, transfer) => {
self.postMessage(message, transfer);
};

0 comments on commit 2ea16db

Please sign in to comment.