Skip to content

Commit

Permalink
Convert sync worker to a module, and to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
psrpinto committed Mar 9, 2023
1 parent 952eccd commit 67153dd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/platform/web/sync/SyncProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export class SyncProxy implements ISync {
}

async start(): Promise<void> {
this._worker = new SharedWorker(new URL("./sync-worker", import.meta.url));
this._worker = new SharedWorker(new URL("./sync-worker", import.meta.url), {
type: "module",
});
this._worker.port.onmessage = (event: MessageEvent) => {
// TODO
console.log(event);
Expand Down
7 changes: 0 additions & 7 deletions src/platform/web/sync/sync-worker.js

This file was deleted.

12 changes: 12 additions & 0 deletions src/platform/web/sync/sync-worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference lib="webworker" />

// The empty export makes this a module. It can be removed once there's at least one import.
export {}

declare let self: SharedWorkerGlobalScope;

self.onconnect = (event: MessageEvent) => {
const port = event.ports[0];
port.postMessage("hello from sync worker");
console.log("hello from sync worker");
}

0 comments on commit 67153dd

Please sign in to comment.