Integrating Electron IPC Handlers with Effect

I'm a bit lost on solving a particular problem around some event listeners.

Imagine I have a program like this:

const program = Effect.gen(function*() {
  // Do some things.
}).pipe(Effect.provideService(AuthStore, authStoreLive))


In some legacy code that I want to move to Effect, I have these Electron IPC handlers.

ipcMain.handle("message", (event, arg1) => {
  return authStoreLive.doSomething(arg1)
})


Note that ipcMain is a global provided by the Electron runtime, and also note that the return value of the handle callback is important, because it's returned back to the process making the IPC.

What I can't figure out is how to set these listeners up inside of my program, run effects, and still return a real value from the callback. Also note that these callbacks are called many times, often several times per second or more. They're not torn down until the application quits.
Was this page helpful?