Troubleshooting `Effect.interrupt` in Fiber Interruption Scenario

Hello, I am trying to figure out why a call to Effect.interrupt doesn't work as expected on a specific scenario:

import { Duration, Effect, Exit, Schedule, pipe } from "effect"

describe("Interrupting Fibert", () => {
    it("Works", async() => {
        const exit = await Effect.runPromiseExit(Effect.gen(function*(_){
            yield*_(
                Effect.log("forked fiber"),
                Effect.repeat(pipe(
                    Schedule.forever,
                    Schedule.addDelay(() => Duration.seconds(1))
                )),
                Effect.fork,
            )


            yield* Effect.log("Sleep")
            yield* Effect.sleep(Duration.seconds(3))
            yield* Effect.log("Awake")
            yield* Effect.interrupt
            yield* Effect.log("Interrupted")
        }))
        
        if (Exit.isSuccess(exit)) throw "unexpected success"
        expect(exit.cause._tag === "Interrupt").toBeTruthy()
    })

    it("Never halts", async() => {
        const exit = await Effect.runPromiseExit(Effect.gen(function*(_){
            yield*_(
                Effect.log("forked fiber"),
                Effect.repeat(Schedule.forever),
                Effect.fork,
            )

            yield* Effect.log("Sleep")
            yield* Effect.sleep(Duration.seconds(3))
            yield* Effect.log("Awake")
            yield* Effect.interrupt
            yield* Effect.log("Interrupted")
        }))
        
        if (Exit.isSuccess(exit)) throw "unexpected success"
        expect(exit.cause._tag === "Interrupt").toBeTruthy()
    })
})
Was this page helpful?