<A>(f: (current: A) => A): (
self: TxSubscriptionRef<A>
) => Effect.Effect<void>
<A>(self: TxSubscriptionRef<A>, f: (current: A) => A): Effect.Effect<void>Updates the value of the TxSubscriptionRef using a function and publishes the new value to all subscribers.
When to use
Use to derive the next TxSubscriptionRef value from the current value and
publish it.
Example (Updating a value)
import { Effect, TxSubscriptionRef } from "effect"
const program = Effect.gen(function*() {
const ref = yield* TxSubscriptionRef.make(5)
yield* TxSubscriptionRef.update(ref, (n) => n * 2)
console.log(yield* TxSubscriptionRef.get(ref)) // 10
})export const const update: {
<A>(f: (current: A) => A): (
self: TxSubscriptionRef<A>
) => Effect.Effect<void>
<A>(
self: TxSubscriptionRef<A>,
f: (current: A) => A
): Effect.Effect<void>
}
Updates the value of the TxSubscriptionRef using a function and publishes the new
value to all subscribers.
When to use
Use to derive the next TxSubscriptionRef value from the current value and
publish it.
Example (Updating a value)
import { Effect, TxSubscriptionRef } from "effect"
const program = Effect.gen(function*() {
const ref = yield* TxSubscriptionRef.make(5)
yield* TxSubscriptionRef.update(ref, (n) => n * 2)
console.log(yield* TxSubscriptionRef.get(ref)) // 10
})
update: {
<function (type parameter) A in <A>(f: (current: A) => A): (self: TxSubscriptionRef<A>) => Effect.Effect<void>A>(f: (current: A) => Af: (current: Acurrent: function (type parameter) A in <A>(f: (current: A) => A): (self: TxSubscriptionRef<A>) => Effect.Effect<void>A) => function (type parameter) A in <A>(f: (current: A) => 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>(f: (current: A) => 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>, f: (current: A) => 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>, f: (current: A) => A): Effect.Effect<void>A>, f: (current: A) => Af: (current: Acurrent: function (type parameter) A in <A>(self: TxSubscriptionRef<A>, f: (current: A) => A): Effect.Effect<void>A) => function (type parameter) A in <A>(self: TxSubscriptionRef<A>, f: (current: A) => 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>, f: (current: A) => 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>, f: (current: A) => A): Effect.Effect<void>A>, f: (current: A) => Af: (current: Acurrent: function (type parameter) A in <A>(self: TxSubscriptionRef<A>, f: (current: A) => A): Effect.Effect<void>A) => function (type parameter) A in <A>(self: TxSubscriptionRef<A>, f: (current: A) => 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, (current: Acurrent) => [void 0, f: (current: A) => Af(current: Acurrent)])
)