Effect CommunityEC
Effect Community9mo ago
3 replies
ynoplanetashka

Nested fork causes fiber interrupt

I was playing with nested forks, but at some point I encountered fiber interruption.
My code:
const program = Effect.gen(function*() {
  const outerFiber = yield* Console.log('1 log').pipe(
    Effect.flatMap(() => Console.log('2 log').pipe(
      Effect.fork
    )),
    Effect.fork
  )
  const innerFiber = yield* Fiber.join(outerFiber);
  yield* Fiber.join(innerFiber);
})

Effect.runPromiseExit(program).then(console.log)

program output:
1 log
{
  _id: 'Exit',
  _tag: 'Failure',
  cause: {
    _id: 'Cause',
    _tag: 'Interrupt',
    fiberId: {
      _id: 'FiberId',
      _tag: 'Runtime',
      id: 1,
      startTimeMillis: 1745996428637
    }
  }
}

It was unexpected for me, I just forked inside fork, without joining it. I wasn't able to find explanation of this in the Effect docs.
Is this behavior actually expected?
Was this page helpful?