Effect CommunityEC
Effect Community2y ago
7 replies
DanSnow

Catching Interrupts in Effect

Hi,

I have a question regarding interrupting effects. Please take a look at the following code example. I expected to be able to catch the interrupt, but it didn't happen. Could someone help me understand why?

const infiniteEffect = pipe(
  Effect.promise(() => new Promise(() => {})),
  Effect.catchAllCause(() => {
    // I expect to catch interrupt here
    console.log('caught interrupt')
    return Effect.void
  }),
)

pipe(
  Effect.gen(function* () {
    const fiber = yield* Effect.fork(infiniteEffect)
    yield* Fiber.interrupt(fiber)
    yield* Fiber.await(fiber)
    console.log('done')
  }),
  Effect.runPromise,
)
Was this page helpful?