(self: TxReentrantLock): Effect.Effect<boolean>Checks whether any fiber holds a read lock.
Example (Checking whether a read lock is held)
import { Effect, TxReentrantLock } from "effect"
const program = Effect.gen(function*() {
const lock = yield* TxReentrantLock.make()
const isReadLocked = yield* TxReentrantLock.readLocked(lock)
console.log(isReadLocked) // false
})getters
Source effect/TxReentrantLock.ts:6035 lines
export const const readLocked: (
self: TxReentrantLock
) => Effect.Effect<boolean>
Checks whether any fiber holds a read lock.
Example (Checking whether a read lock is held)
import { Effect, TxReentrantLock } from "effect"
const program = Effect.gen(function*() {
const lock = yield* TxReentrantLock.make()
const isReadLocked = yield* TxReentrantLock.readLocked(lock)
console.log(isReadLocked) // false
})
readLocked = (self: TxReentrantLock(parameter) self: {
stateRef: TxRef.TxRef<LockState>;
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: TxReentrantLock): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<boolean> =>
import EffectEffect.gen(function*() {
const const state: anyconst state: {
readers: HashMap.HashMap<number, number>;
writer: Option.Option<readonly [fiberId: number, count: number]>;
}
state = yield* import TxRefTxRef.const get: <A>(
self: TxRef<A>
) => Effect.Effect<A>
Reads the current value of the TxRef.
When to use
Use to read the current value of a TxRef.
Example (Reading transactional references)
import { Effect, TxRef } from "effect"
const program = Effect.gen(function*() {
const counter = yield* TxRef.make(42)
// Read the value within a transaction
const value = yield* Effect.tx(
TxRef.get(counter)
)
console.log(value) // 42
})
get(self: TxReentrantLock(parameter) self: {
stateRef: TxRef.TxRef<LockState>;
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.TxReentrantLock.stateRef: TxRef.TxRef<LockState>(property) TxReentrantLock.stateRef: {
version: number;
pending: Map<unknown, () => void>;
value: 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; <…;
}
stateRef)
return import HashMapHashMap.size(const state: anyconst state: {
readers: HashMap.HashMap<number, number>;
writer: Option.Option<readonly [fiberId: number, count: number]>;
}
state.readers) > 0
})