Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
samwillis committed Jul 30, 2024
1 parent bf85a5d commit 139f1da
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/pglite/examples/worker-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { vector } from "../dist/vector/index.js";
worker({
async init() {
const pg = new PGlite({
dataDir: "idb://worker-example",
debug:1,
extensions: {
vector,
},
Expand Down
7 changes: 6 additions & 1 deletion packages/pglite/src/worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export class PGliteWorker implements PGliteInterface {
});

this.#broadcastChannel.addEventListener("message", async (event) => {
// console.log("broadcast message", event.data);
if (event.data.type === "leader-here") {
this.#connected = false;
this.#eventTarget.dispatchEvent(new Event("leader-change"));
Expand All @@ -170,6 +171,7 @@ export class PGliteWorker implements PGliteInterface {
});

this.#tabChannel.addEventListener("message", async (event) => {
// console.log("tab message", event.data);
if (event.data.type === "connected") {
this.#connected = true;
this.#eventTarget.dispatchEvent(new Event("connected"));
Expand All @@ -179,6 +181,7 @@ export class PGliteWorker implements PGliteInterface {
});

this.#workerProcess.addEventListener("message", async (event) => {
// console.log("worker message", event.data);
if (event.data.type === "leader-now") {
this.#isLeader = true;
this.#eventTarget.dispatchEvent(new Event("leader-change"));
Expand Down Expand Up @@ -597,6 +600,7 @@ function connectTab(
const api = makeWorkerApi(pg);

tabChannel.addEventListener("message", async (event) => {
// console.log("worker: tab message", event.data);
const msg = event.data;
switch (msg.type) {
case "rpc-call":
Expand All @@ -612,10 +616,11 @@ function connectTab(
result,
} satisfies WorkerRpcResult<typeof method>);
} catch (error) {
console.error(error);
tabChannel.postMessage({
type: "rpc-error",
callId,
error,
error: { message: (error as Error).message },
} satisfies WorkerRpcError);
}
break;
Expand Down
2 changes: 1 addition & 1 deletion packages/pglite/tests/targets/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export function tests(env, dbFilename, target) {
});
});

if (env === "node") {
if (env === "node" || env === "webkit") {
// Skip the rest of the tests for node as they are browser specific
return;
}
Expand Down

0 comments on commit 139f1da

Please sign in to comment.