Hyperlinkv0.8.0-beta.28

PubSub

PubSub.shutdownconsteffect/PubSub.ts:757
<A>(self: PubSub<A>): Effect.Effect<void>

Shuts down the PubSub, interrupting suspended publishers and subscribers and finalizing active subscriptions.

Details

After shutdown, publish and publishAll succeed with false, publishUnsafe returns false, and subscription operations such as take interrupt.

Example (Shutting down a PubSub)

import { Effect, PubSub } from "effect"

const program = Effect.gen(function*() {
  const pubsub = yield* PubSub.bounded<string>(1)

  // Shutdown the PubSub
  yield* PubSub.shutdown(pubsub)

  const isShutdown = yield* PubSub.isShutdown(pubsub)
  console.log("Is shutdown:", isShutdown) // true

  // Publishing after shutdown returns false
  const published = yield* PubSub.publish(pubsub, "msg1")
  console.log("Published after shutdown:", published) // false
})
lifecycle
Source effect/PubSub.ts:7579 lines
export const shutdown = <A>(self: PubSub<A>): Effect.Effect<void> =>
  Effect.uninterruptible(Effect.withFiber((fiber) => {
    MutableRef.set(self.shutdownFlag, true)
    return Scope.close(self.scope, Exit.interrupt(fiber.id)).pipe(
      Effect.andThen(self.strategy.shutdown),
      Effect.when(self.shutdownHook.open),
      Effect.asVoid
    )
  }))
Referenced by 2 symbols