<A>(value: A): (self: TxSubscriptionRef<A>) => Effect.Effect<void>
<A>(self: TxSubscriptionRef<A>, value: A): Effect.Effect<void>Sets the value of the TxSubscriptionRef and publishes the new value to all subscribers.
When to use
Use to replace the current TxSubscriptionRef value with a known value and
publish it.
Example (Setting a new value)
import { Effect, TxSubscriptionRef } from "effect"
const program = Effect.gen(function*() {
const ref = yield* TxSubscriptionRef.make(0)
yield* TxSubscriptionRef.set(ref, 42)
console.log(yield* TxSubscriptionRef.get(ref)) // 42
})export const const set: {
<A>(value: A): (
self: TxSubscriptionRef<A>
) => Effect.Effect<void>
<A>(
self: TxSubscriptionRef<A>,
value: A
): Effect.Effect<void>
}
Sets the value of the TxSubscriptionRef and publishes the new value to all subscribers.
When to use
Use to replace the current TxSubscriptionRef value with a known value and
publish it.
Example (Setting a new value)
import { Effect, TxSubscriptionRef } from "effect"
const program = Effect.gen(function*() {
const ref = yield* TxSubscriptionRef.make(0)
yield* TxSubscriptionRef.set(ref, 42)
console.log(yield* TxSubscriptionRef.get(ref)) // 42
})
set: {
<function (type parameter) A in <A>(value: A): (self: TxSubscriptionRef<A>) => Effect.Effect<void>A>(value: Avalue: function (type parameter) A in <A>(value: A): (self: TxSubscriptionRef<A>) => Effect.Effect<void>A): (self: TxSubscriptionRef<A>(parameter) self: {
ref: TxRef.TxRef<A>;
pubsub: TxPubSub.TxPubSub<A>;
toString: () => string;
toJSON: () => unknown;
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 TxSubscriptionRef<in out A>A TxSubscriptionRef is a transactional reference that allows subscribing to all
committed changes. Subscribers receive the current value followed by every subsequent
update via a transactional dequeue.
When to use
Use to store transactional state whose committed changes must be observable by
subscribers.
Example (Subscribing to transactional changes)
import { Effect, TxQueue, TxSubscriptionRef } from "effect"
const program = Effect.gen(function*() {
const ref = yield* TxSubscriptionRef.make(0)
yield* Effect.scoped(
Effect.gen(function*() {
const sub = yield* TxSubscriptionRef.changes(ref)
const initial = yield* TxQueue.take(sub)
console.log(initial) // 0
yield* TxSubscriptionRef.set(ref, 1)
const next = yield* TxQueue.take(sub)
console.log(next) // 1
})
)
})
TxSubscriptionRef<function (type parameter) A in <A>(value: A): (self: TxSubscriptionRef<A>) => Effect.Effect<void>A>) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<void>
<function (type parameter) A in <A>(self: TxSubscriptionRef<A>, value: A): Effect.Effect<void>A>(self: TxSubscriptionRef<A>(parameter) self: {
ref: TxRef.TxRef<A>;
pubsub: TxPubSub.TxPubSub<A>;
toString: () => string;
toJSON: () => unknown;
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 TxSubscriptionRef<in out A>A TxSubscriptionRef is a transactional reference that allows subscribing to all
committed changes. Subscribers receive the current value followed by every subsequent
update via a transactional dequeue.
When to use
Use to store transactional state whose committed changes must be observable by
subscribers.
Example (Subscribing to transactional changes)
import { Effect, TxQueue, TxSubscriptionRef } from "effect"
const program = Effect.gen(function*() {
const ref = yield* TxSubscriptionRef.make(0)
yield* Effect.scoped(
Effect.gen(function*() {
const sub = yield* TxSubscriptionRef.changes(ref)
const initial = yield* TxQueue.take(sub)
console.log(initial) // 0
yield* TxSubscriptionRef.set(ref, 1)
const next = yield* TxQueue.take(sub)
console.log(next) // 1
})
)
})
TxSubscriptionRef<function (type parameter) A in <A>(self: TxSubscriptionRef<A>, value: A): Effect.Effect<void>A>, value: Avalue: function (type parameter) A in <A>(self: TxSubscriptionRef<A>, value: A): Effect.Effect<void>A): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<void>
} = import dualdual(
2,
<function (type parameter) A in <A>(self: TxSubscriptionRef<A>, value: A): Effect.Effect<void>A>(self: TxSubscriptionRef<A>(parameter) self: {
ref: TxRef.TxRef<A>;
pubsub: TxPubSub.TxPubSub<A>;
toString: () => string;
toJSON: () => unknown;
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 TxSubscriptionRef<in out A>A TxSubscriptionRef is a transactional reference that allows subscribing to all
committed changes. Subscribers receive the current value followed by every subsequent
update via a transactional dequeue.
When to use
Use to store transactional state whose committed changes must be observable by
subscribers.
Example (Subscribing to transactional changes)
import { Effect, TxQueue, TxSubscriptionRef } from "effect"
const program = Effect.gen(function*() {
const ref = yield* TxSubscriptionRef.make(0)
yield* Effect.scoped(
Effect.gen(function*() {
const sub = yield* TxSubscriptionRef.changes(ref)
const initial = yield* TxQueue.take(sub)
console.log(initial) // 0
yield* TxSubscriptionRef.set(ref, 1)
const next = yield* TxQueue.take(sub)
console.log(next) // 1
})
)
})
TxSubscriptionRef<function (type parameter) A in <A>(self: TxSubscriptionRef<A>, value: A): Effect.Effect<void>A>, value: Avalue: function (type parameter) A in <A>(self: TxSubscriptionRef<A>, value: A): Effect.Effect<void>A): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<void> => const modify: {
<A, B>(
f: (
current: A
) => [returnValue: B, newValue: A]
): (
self: TxSubscriptionRef<A>
) => Effect.Effect<B>
<A, B>(
self: TxSubscriptionRef<A>,
f: (
current: A
) => [returnValue: B, newValue: A]
): Effect.Effect<B>
}
modify(self: TxSubscriptionRef<A>(parameter) self: {
ref: TxRef.TxRef<A>;
pubsub: TxPubSub.TxPubSub<A>;
toString: () => string;
toJSON: () => unknown;
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, () => [void 0, value: Avalue])
)