<A>(self: PubSub<A>): Effect.Effect<void>Waits until the queue is shutdown. The Effect returned by this method will
not resume until the queue has been shutdown. If the queue is already
shutdown, the Effect will resume right away.
Example (Waiting for shutdown)
import { Effect, Fiber, PubSub } from "effect"
const program = Effect.gen(function*() {
const pubsub = yield* PubSub.bounded<string>(10)
// Start a fiber that waits for shutdown
const waiterFiber = yield* Effect.forkChild(
Effect.gen(function*() {
yield* PubSub.awaitShutdown(pubsub)
console.log("PubSub has been shutdown!")
})
)
// Do some work...
yield* Effect.sleep("100 millis")
// Shutdown the PubSub
yield* PubSub.shutdown(pubsub)
// The waiter will now complete
yield* Fiber.join(waiterFiber)
})export const const awaitShutdown: <A>(
self: PubSub<A>
) => Effect.Effect<void>
Waits until the queue is shutdown. The Effect returned by this method will
not resume until the queue has been shutdown. If the queue is already
shutdown, the Effect will resume right away.
Example (Waiting for shutdown)
import { Effect, Fiber, PubSub } from "effect"
const program = Effect.gen(function*() {
const pubsub = yield* PubSub.bounded<string>(10)
// Start a fiber that waits for shutdown
const waiterFiber = yield* Effect.forkChild(
Effect.gen(function*() {
yield* PubSub.awaitShutdown(pubsub)
console.log("PubSub has been shutdown!")
})
)
// Do some work...
yield* Effect.sleep("100 millis")
// Shutdown the PubSub
yield* PubSub.shutdown(pubsub)
// The waiter will now complete
yield* Fiber.join(waiterFiber)
})
awaitShutdown = <function (type parameter) A in <A>(self: PubSub<A>): Effect.Effect<void>A>(self: PubSub<A>(parameter) self: {
pubsub: PubSub.Atomic<A>;
subscribers: PubSub.Subscribers<A>;
scope: Scope.Closeable;
shutdownHook: Latch.Latch;
shutdownFlag: MutableRef.MutableRef<boolean>;
strategy: PubSub.Strategy<A>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: interface PubSub<in out A>A PubSub<A> is an asynchronous message hub into which publishers can publish
messages of type A and subscribers can subscribe to take messages of type
A.
Example (Publishing and subscribing to messages)
import { Effect, PubSub } from "effect"
const program = Effect.gen(function*() {
// Create a bounded PubSub with capacity 10
const pubsub = yield* PubSub.bounded<string>(10)
// Subscribe and consume messages
yield* Effect.scoped(Effect.gen(function*() {
const subscription = yield* PubSub.subscribe(pubsub)
// Publish messages
yield* PubSub.publish(pubsub, "Hello")
yield* PubSub.publish(pubsub, "World")
const message1 = yield* PubSub.take(subscription)
const message2 = yield* PubSub.take(subscription)
console.log(message1, message2) // "Hello", "World"
}))
})
Companion namespace containing the low-level building blocks used by
PubSub, including atomic implementations, backing subscriptions, replay
windows, and delivery strategies.
PubSub<function (type parameter) A in <A>(self: PubSub<A>): Effect.Effect<void>A>): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<void> => self: PubSub<A>(parameter) self: {
pubsub: PubSub.Atomic<A>;
subscribers: PubSub.Subscribers<A>;
scope: Scope.Closeable;
shutdownHook: Latch.Latch;
shutdownFlag: MutableRef.MutableRef<boolean>;
strategy: PubSub.Strategy<A>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self.PubSub<in out A>.shutdownHook: Latch.Latch(property) PubSub<in out A>.shutdownHook: {
open: Effect.Effect<boolean>;
openUnsafe: (this: Latch) => boolean;
release: Effect.Effect<boolean>;
await: Effect.Effect<void>;
close: Effect.Effect<boolean>;
closeUnsafe: (this: Latch) => boolean;
whenOpen: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
isOpen: (this: Latch) => boolean;
}
shutdownHook.await