Handling Resource Disposal with Finalizers in Svelte When Fiber Gets Interrupted

Hi everyone, I'm trying to dispose my resources using finalizer but my finalizer isn't called when the fiber gets interrupted.

I manage to create an effect stream that listens to new messages over websockets when the component mounts. Next step is to close it when the component unmounts. This is the code I've got so far (in Svelte specifically):

let fiber;

onMount(() => {
    fiber = runtime.runFork(
        Effect.scoped(
            Effect.gen(function* () {
                const stream = yield* newCommentsStreamEffect();
                yield* Effect.addFinalizer((e) => {
                    console.log('i will cancel the stream here but it this doesnt execute');
                    return Effect.void;
                });
                yield* pipe(
                    stream,
                    Stream.runForEach((a) => {
                        // i can process my message here
                        return Effect.void;
                    })
                );
            })
        )
    );
});

onDestroy(() => {
    // This executes, however the finalizer doesn't (log doesn't print)
    Effect.runFork(Fiber.interrupt(fiber));
});
Was this page helpful?