Effect CommunityEC
Effect Community3mo ago
20 replies
Stephen Bluck

Why aren't these `Fiber`'s getting interrupted?

I have a small program boxed up into a layer. My expectation is to see two logs when I terminate my program however I only see "Worker shutting down" and nothing past this such as "Worker shut down". What am I doing wrong?

When I remove the Fiber.interrupt(fiber), I see both logs.

const ProgramLive = Layer.scopedDiscard(
  Effect.gen(function* () {
    const eventProcessor = yield* EventProcessor;
    const notificationConsumer = yield* NotificationConsumer;

    const fiber = yield* Effect.forkAll([eventProcessor.start, notificationConsumer.consume.pipe(Stream.runDrain)]);

    yield* Effect.addFinalizer(() =>
      Effect.log('Worker shutting down').pipe(
        Effect.flatMap(() => Fiber.interrupt(fiber)),
        Effect.tap(exit => Effect.log('Worker shut down', { exit }))
      )
    );
  })
).pipe(
  Layer.provide(
    Layer.mergeAll(
      NotificationConsumer.Default,
      EventProcessor.Default({ repeatSchedule: Schedule.fixed(Duration.seconds(5)) })
    )
  )
);

const AppLive = Layer.mergeAll(ProgramLive, Server).pipe(Layer.provide(LoggerLive));

Layer.launch(AppLive).pipe(
  NodeRuntime.runMain({
    disablePrettyLogger: true,
  })
);
Was this page helpful?