<A>(value: A): Effect.Effect<SubscriptionRef<A>>Constructs a new SubscriptionRef from an initial value.
When to use
Use to create a SubscriptionRef when consumers need to read the latest
value and subscribe to every update.
Details
The initial value is published during construction, so changes starts new
subscribers with that value before future updates.
export const const make: <A>(
value: A
) => Effect.Effect<SubscriptionRef<A>>
Constructs a new SubscriptionRef from an initial value.
When to use
Use to create a SubscriptionRef when consumers need to read the latest
value and subscribe to every update.
Details
The initial value is published during construction, so changes starts new
subscribers with that value before future updates.
make = <function (type parameter) A in <A>(value: A): Effect.Effect<SubscriptionRef<A>>A>(value: Avalue: function (type parameter) A in <A>(value: A): Effect.Effect<SubscriptionRef<A>>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<interface SubscriptionRef<in out A>A mutable reference whose updates are serialized and published to
subscribers.
When to use
Use to observe the current value and subsequent updates as a
stream.
The SubscriptionRef namespace containing type definitions associated with
subscription references.
SubscriptionRef<function (type parameter) A in <A>(value: A): Effect.Effect<SubscriptionRef<A>>A>> =>
import EffectEffect.const map: {
<A, B>(f: (a: A) => B): <E, R>(
self: Effect<A, E, R>
) => Effect<B, E, R>
<A, E, R, B>(
self: Effect<A, E, R>,
f: (a: A) => B
): Effect<B, E, R>
}
map(import PubSubPubSub.const unbounded: <A>(options?: {
readonly replay?: number | undefined
}) => Effect.Effect<PubSub<A>>
Creates an unbounded PubSub.
Example (Creating an unbounded PubSub)
import { Effect, PubSub } from "effect"
const program = Effect.gen(function*() {
// Create unbounded PubSub
const pubsub = yield* PubSub.unbounded<string>()
// With replay buffer for late subscribers
const pubsubWithReplay = yield* PubSub.unbounded<string>({
replay: 10
})
yield* Effect.scoped(Effect.gen(function*() {
const subscription = yield* PubSub.subscribe(pubsub)
// Can publish unlimited messages
for (let i = 0; i < 3; i++) {
yield* PubSub.publish(pubsub, `message-${i}`)
}
const message = yield* PubSub.take(subscription)
console.log("First message:", message) // "message-0"
}))
})
unbounded<function (type parameter) A in <A>(value: A): Effect.Effect<SubscriptionRef<A>>A>({ replay?: number | undefinedreplay: 1 }), (pubsub: PubSub.PubSub<A>(parameter) pubsub: {
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; <…;
}
pubsub) => {
const const self: anyself = var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.create(o: object | null): any (+1 overload)Creates an object that has the specified prototype or that has null prototype.
create(const Proto: {
"~effect/SubscriptionRef": {
_A: <A>(a: A) => A
}
toJSON(this: SubscriptionRef<unknown>): {
_id: string
value: unknown
}
pipe(): unknown
toString(): string
[NodeInspectSymbol](): any
}
Proto)
const self: anyself.semaphore = import SemaphoreSemaphore.const makeUnsafe: (
permits: number
) => Semaphore
Creates a Semaphore synchronously with the specified total
number of permits.
When to use
Use to construct a semaphore synchronously when an immediate value is
required outside an Effect workflow.
Example (Creating an unsafe semaphore)
import { Effect, Semaphore } from "effect"
const semaphore = Semaphore.makeUnsafe(3)
const task = (id: number) =>
semaphore.withPermits(1)(
Effect.gen(function*() {
yield* Effect.log(`Task ${id} started`)
yield* Effect.sleep("1 second")
yield* Effect.log(`Task ${id} completed`)
})
)
// Only 3 tasks can run concurrently
const program = Effect.all([
task(1),
task(2),
task(3),
task(4),
task(5)
], { concurrency: "unbounded" })
makeUnsafe(1)
const self: anyself.value = value: Avalue
const self: anyself.pubsub = pubsub: PubSub.PubSub<A>(parameter) pubsub: {
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; <…;
}
pubsub
import PubSubPubSub.const publishUnsafe: {
<A>(value: A): (self: PubSub<A>) => boolean
<A>(self: PubSub<A>, value: A): boolean
}
publishUnsafe(const self: anyself.pubsub, value: Avalue)
return const self: anyself
})