Effect CommunityEC
Effect Community14mo ago
9 replies
ikigai

Running `@effect/sql-kysely` with `@effect/sql-sqlite-wasm` in a Browser Web Worker

I am trying to run @effect/sql-kysely package with @effect/sql-sqlite-wasm on the browser web worker using @effect/platform-browser.

You can find my code git@github.com:bhvngt/effect-webworker-kysely.git

I am getting following error in the browser console while returning Proxy object returned from kysely execution.

Uncaught (in promise) (FiberFailure) TypeError: Cannot use 'in' operator to search for 'Symbol(effect/Effect)' in null

When I run the same code on node, it works fine (./src/scratch.ts file in my repo works well when run on node).

Here's main thread and worker code

main thread
  import * as EffectWorker from "@effect/platform/Worker";
  import { Effect } from "effect";
  import { AddUser, User } from "./worker/schema";

  let user: User | null;
  const program = Effect.gen(function* () {
    const pool = yield* EffectWorker.makePoolSerialized({ size: 1 });
    user = yield* pool.executeEffect(new AddUser({ id: Math.round(Math.random() * 100) }));
  }).pipe(Effect.scoped, Effect.provide(BrowserWorker.layer(() =>
    new Worker(new URL("./worker/serializedWorker.ts", import.meta.url), { type: "module" }),
  )));

  async function addRecord() {
    await Effect.runPromise(program);
  }
Was this page helpful?