<A>(value: A): (self: TxSubscriptionRef<A>) => Effect.Effect<A>
<A>(self: TxSubscriptionRef<A>, value: A): Effect.Effect<A>Gets the current value and sets a new value atomically. Publishes the new value to all subscribers.
When to use
Use to replace a TxSubscriptionRef value while returning the previous value
and publishing the update to subscribers.
Example (Getting and setting atomically)
import { Effect, TxSubscriptionRef } from "effect"
const program = Effect.gen(function*() {
const ref = yield* TxSubscriptionRef.make("a")
const old = yield* TxSubscriptionRef.getAndSet(ref, "b")
console.log(old) // "a"
console.log(yield* TxSubscriptionRef.get(ref)) // "b"
})export const const getAndSet: {
<A>(value: A): (
self: TxSubscriptionRef<A>
) => Effect.Effect<A>
<A>(
self: TxSubscriptionRef<A>,
value: A
): Effect.Effect<A>
}
Gets the current value and sets a new value atomically. Publishes the new value
to all subscribers.
When to use
Use to replace a TxSubscriptionRef value while returning the previous value
and publishing the update to subscribers.
Example (Getting and setting atomically)
import { Effect, TxSubscriptionRef } from "effect"
const program = Effect.gen(function*() {
const ref = yield* TxSubscriptionRef.make("a")
const old = yield* TxSubscriptionRef.getAndSet(ref, "b")
console.log(old) // "a"
console.log(yield* TxSubscriptionRef.get(ref)) // "b"
})
getAndSet: {
<function (type parameter) A in <A>(value: A): (self: TxSubscriptionRef<A>) => Effect.Effect<A>A>(value: Avalue: function (type parameter) A in <A>(value: A): (self: TxSubscriptionRef<A>) => Effect.Effect<A>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<A>A>) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<function (type parameter) A in <A>(value: A): (self: TxSubscriptionRef<A>) => Effect.Effect<A>A>
<function (type parameter) A in <A>(self: TxSubscriptionRef<A>, value: A): Effect.Effect<A>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<A>A>, value: Avalue: function (type parameter) A in <A>(self: TxSubscriptionRef<A>, value: A): Effect.Effect<A>A): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<function (type parameter) A in <A>(self: TxSubscriptionRef<A>, value: A): Effect.Effect<A>A>
} = import dualdual(
2,
<function (type parameter) A in <A>(self: TxSubscriptionRef<A>, value: A): Effect.Effect<A>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<A>A>, value: Avalue: function (type parameter) A in <A>(self: TxSubscriptionRef<A>, value: A): Effect.Effect<A>A): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<function (type parameter) A in <A>(self: TxSubscriptionRef<A>, value: A): Effect.Effect<A>A> => 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, (current: Acurrent) => [current: Acurrent, value: Avalue])
)