Skip to content

Commit

Permalink
Dispose fiber on effect controller
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepyfran committed Sep 9, 2024
1 parent 4ea8edc commit a894bdf
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
getOrCreateRuntime,
type EchoRuntimeServices,
} from "@echo/services-bootstrap-runtime";
import { Effect } from "effect";
import { Effect, Fiber } from "effect";
import type { ReactiveController, ReactiveControllerHost } from "lit";
import type { StatusListener } from "./shared.interface";

Expand All @@ -18,6 +18,7 @@ type StreamStatus<A, E> =
*/
export class EffectFn<P, A, E> implements ReactiveController {
private host: ReactiveControllerHost;
private _fiber: Fiber.RuntimeFiber<void, E> | undefined;
private _status: StreamStatus<A, E> = { _tag: "Initial" };

constructor(
Expand All @@ -38,6 +39,13 @@ export class EffectFn<P, A, E> implements ReactiveController {

hostConnected(): void {}

hostDisconnected(): void {
if (this._fiber) {
getOrCreateRuntime().runFork(Fiber.interrupt(this._fiber));
this._fiber = undefined;
}
}

/**
* Runs the effect with the given parameters. This produces a value or an error
* that gets notified to the host and triggers the listeners if they are provided.
Expand Down

0 comments on commit a894bdf

Please sign in to comment.