<A>(self: PubSub<A>): Effect.Effect<boolean>Checks effectfully whether shutdown has been called, returning true
after shutdown and false otherwise.
Example (Checking whether a PubSub is shut down)
import { Effect, PubSub } from "effect"
const program = Effect.gen(function*() {
const pubsub = yield* PubSub.bounded<string>(10)
// Initially not shutdown
const initiallyShutdown = yield* PubSub.isShutdown(pubsub)
console.log("Initially shutdown:", initiallyShutdown) // false
// Shutdown the PubSub
yield* PubSub.shutdown(pubsub)
const nowShutdown = yield* PubSub.isShutdown(pubsub)
console.log("Now shutdown:", nowShutdown) // true
})export const const isShutdown: <A>(
self: PubSub<A>
) => Effect.Effect<boolean>
Checks effectfully whether shutdown has been called, returning true
after shutdown and false otherwise.
Example (Checking whether a PubSub is shut down)
import { Effect, PubSub } from "effect"
const program = Effect.gen(function*() {
const pubsub = yield* PubSub.bounded<string>(10)
// Initially not shutdown
const initiallyShutdown = yield* PubSub.isShutdown(pubsub)
console.log("Initially shutdown:", initiallyShutdown) // false
// Shutdown the PubSub
yield* PubSub.shutdown(pubsub)
const nowShutdown = yield* PubSub.isShutdown(pubsub)
console.log("Now shutdown:", nowShutdown) // true
})
isShutdown = <function (type parameter) A in <A>(self: PubSub<A>): Effect.Effect<boolean>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<boolean>A>): import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<boolean> => import EffectEffect.const sync: <A>(
thunk: LazyArg<A>
) => Effect<A>
Creates an Effect that represents a synchronous side-effectful computation.
When to use
Use when you need to wrap a synchronous side-effectful operation that is not
expected to throw.
Details
The provided function is evaluated lazily when the effect runs.
Gotchas
The function must not throw. If it throws, the thrown value is treated as a
defect, not as a typed failure. Use try when throwing is expected.
Example (Capturing synchronous logging in an Effect)
import { Effect } from "effect"
const log = (message: string) =>
Effect.sync(() => {
console.log(message) // side effect
})
// ┌─── Effect<void, never, never>
// ▼
const program = log("Hello, World!")
sync(() => const isShutdownUnsafe: <A>(
self: PubSub<A>
) => boolean
Checks synchronously whether shutdown has been called, returning true
after shutdown and false otherwise.
When to use
Use when an immediate PubSub shutdown-state snapshot is needed outside
effectful code and racing shutdown changes are acceptable.
Example (Checking shutdown synchronously)
import { PubSub } from "effect"
declare const pubsub: PubSub.PubSub<string>
// Unsafe synchronous shutdown check
const isDown = PubSub.isShutdownUnsafe(pubsub)
if (isDown) {
console.log("PubSub is shutdown, cannot publish")
} else {
console.log("PubSub is active")
}
isShutdownUnsafe(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))