Effect CommunityEC
Effect Community3y ago
63 replies
TheStockBroker

Debugging Effect Integration with React

I am absolutely shattered. I've spent the entire day trying to debug why I get cause="All fibers interrupted without errors." on all my Effect.logs. I'm trying to integration effect with react. I am never in the entire lifespan of the app ever ever close a scope. I even stuck finalizers on the lone scope I do have to shout at me if I accidentally close it.
I'm passing around a Effect<never, E, Runtime<R>>, the Scope attached to this effect is manually controlled and never closed. I provide it using Effect.provideService(Scope, scope) because I know Effect.scoped and Scope.use and similar have termination triggers.
I would pass around the constructed Runtime<R> but it's constructed async so I pass around an Effect.cached version of the effect that would yield it.

I then later consume with the following eye-watering pattern:
(note, this is abridged. But theres nothing interesting I omitted)
const wrap = (effect: Effect<R,E,A>) => {
  Effect.flatMap(runtimeEffect, runtime => {
    const run = Runtime.runCallback(runtime)

    const interrupt = Effect.asyncInterrupt((resume) => run(effect, exit => resume(Exit.match(exit, Effect.succeed, Effect.failCause))))
    return () => interrupt()
}

and the resulting effect is then passed to an Effect.runCallback to sync it to my react state, theres also a similar clone of the interruption model on that level as well.
This is heavily inspired by @Tim Smarts work, modified (or more aptly, broken) by yours truly.

TL;DR:
effect -> runtime -> used in callback -> run with callback
runtime is perma closed, meaning all my scoped effects, even if manually scoped, break with service not found.
Was this page helpful?