(u: unknown): u is TxSubscriptionRef<unknown>Checks whether the given value is a TxSubscriptionRef.
When to use
Use to narrow an unknown value before treating it as a TxSubscriptionRef.
Example (Checking transactional subscription references)
import { TxSubscriptionRef } from "effect"
declare const someValue: unknown
if (TxSubscriptionRef.isTxSubscriptionRef(someValue)) {
console.log("This is a TxSubscriptionRef")
}guardsmake
Source effect/TxSubscriptionRef.ts:5181 lines
export const const isTxSubscriptionRef: (
u: unknown
) => u is TxSubscriptionRef<unknown>
Checks whether the given value is a TxSubscriptionRef.
When to use
Use to narrow an unknown value before treating it as a TxSubscriptionRef.
Example (Checking transactional subscription references)
import { TxSubscriptionRef } from "effect"
declare const someValue: unknown
if (TxSubscriptionRef.isTxSubscriptionRef(someValue)) {
console.log("This is a TxSubscriptionRef")
}
isTxSubscriptionRef = (u: unknownu: unknown): u: unknownu is 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<unknown> => import hasPropertyhasProperty(u: unknownu, const TypeId: "~effect/transactions/TxSubscriptionRef"TypeId)