<A>(options: {
readonly atomicPubSub: LazyArg<PubSub.Atomic<A>>
readonly strategy: LazyArg<PubSub.Strategy<A>>
}): Effect.Effect<PubSub<A>>Creates a PubSub with a custom atomic implementation and strategy.
Example (Creating a PubSub with a custom strategy)
import { Effect, PubSub } from "effect"
const program = Effect.gen(function*() {
// Create custom PubSub with specific atomic implementation and strategy
const pubsub = yield* PubSub.make<string>({
atomicPubSub: () => PubSub.makeAtomicBounded(100),
strategy: () => new PubSub.BackPressureStrategy()
})
// Use the created PubSub
yield* PubSub.publish(pubsub, "Hello")
})export const const make: <A>(options: {
readonly atomicPubSub: LazyArg<PubSub.Atomic<A>>
readonly strategy: LazyArg<PubSub.Strategy<A>>
}) => Effect.Effect<PubSub<A>>
Creates a PubSub with a custom atomic implementation and strategy.
Example (Creating a PubSub with a custom strategy)
import { Effect, PubSub } from "effect"
const program = Effect.gen(function*() {
// Create custom PubSub with specific atomic implementation and strategy
const pubsub = yield* PubSub.make<string>({
atomicPubSub: () => PubSub.makeAtomicBounded(100),
strategy: () => new PubSub.BackPressureStrategy()
})
// Use the created PubSub
yield* PubSub.publish(pubsub, "Hello")
})
make = <function (type parameter) A in <A>(options: {
readonly atomicPubSub: LazyArg<PubSub.Atomic<A>>;
readonly strategy: LazyArg<PubSub.Strategy<A>>;
}): Effect.Effect<PubSub<A>>
A>(
options: {
readonly atomicPubSub: LazyArg<PubSub.Atomic<A>>
readonly strategy: LazyArg<PubSub.Strategy<A>>
}
options: {
readonly atomicPubSub: LazyArg<PubSub.Atomic<A>>atomicPubSub: import LazyArgLazyArg<PubSub.interface PubSub<in out A>.Atomic<in out A>Low-level atomic PubSub interface that handles the core message storage and retrieval.
Atomic<function (type parameter) A in <A>(options: {
readonly atomicPubSub: LazyArg<PubSub.Atomic<A>>;
readonly strategy: LazyArg<PubSub.Strategy<A>>;
}): Effect.Effect<PubSub<A>>
A>>
readonly strategy: LazyArg<PubSub.Strategy<A>>strategy: import LazyArgLazyArg<PubSub.interface PubSub<in out A>.Strategy<in out A>Strategy interface defining how PubSub handles backpressure and message distribution.
Strategy<function (type parameter) A in <A>(options: {
readonly atomicPubSub: LazyArg<PubSub.Atomic<A>>;
readonly strategy: LazyArg<PubSub.Strategy<A>>;
}): Effect.Effect<PubSub<A>>
A>>
}
): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<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>(options: {
readonly atomicPubSub: LazyArg<PubSub.Atomic<A>>;
readonly strategy: LazyArg<PubSub.Strategy<A>>;
}): Effect.Effect<PubSub<A>>
A>> =>
import EffectEffect.sync(() =>
const makePubSubUnsafe: <A>(
pubsub: PubSub.Atomic<A>,
subscribers: PubSub.Subscribers<A>,
scope: Scope.Closeable,
shutdownHook: Latch.Latch,
shutdownFlag: MutableRef.MutableRef<boolean>,
strategy: PubSub.Strategy<A>
) => PubSub<A>
makePubSubUnsafe(
options: {
readonly atomicPubSub: LazyArg<PubSub.Atomic<A>>
readonly strategy: LazyArg<PubSub.Strategy<A>>
}
options.atomicPubSub: LazyArg<PubSub.Atomic<A>>atomicPubSub(),
new var Map: MapConstructor
new () => Map<any, any> (+3 overloads)
Map(),
import ScopeScope.const makeUnsafe: (
finalizerStrategy?: "sequential" | "parallel"
) => Closeable
Creates a new Scope synchronously without wrapping it in an Effect.
This is useful when you need a scope immediately but should be used with caution
as it doesn't provide the same safety guarantees as the Effect-wrapped version.
When to use
Use when a scope must be allocated synchronously and the caller will close it
manually.
Example (Creating a scope synchronously)
import { Console, Effect, Exit, Scope } from "effect"
// Create a scope immediately
const scope = Scope.makeUnsafe("sequential")
// Use it in an Effect program
const program = Effect.gen(function*() {
yield* Scope.addFinalizer(scope, Console.log("Cleanup"))
yield* Scope.close(scope, Exit.void)
})
makeUnsafe(),
import LatchLatch.makeUnsafe(false),
import MutableRefMutableRef.make(false),
options: {
readonly atomicPubSub: LazyArg<PubSub.Atomic<A>>
readonly strategy: LazyArg<PubSub.Strategy<A>>
}
options.strategy: LazyArg<PubSub.Strategy<A>>strategy()
)
)