(self: TxReentrantLock): Effect.Effect<number>Returns the number of write locks held (0 or the reentrant count).
Example (Counting write locks)
import { Effect, TxReentrantLock } from "effect"
const program = Effect.gen(function*() {
const lock = yield* TxReentrantLock.make()
const count = yield* TxReentrantLock.writeLocks(lock)
console.log(count) // 0
})getters
Source effect/TxReentrantLock.ts:5555 lines
export const const writeLocks: (
self: TxReentrantLock
) => Effect.Effect<number>
Returns the number of write locks held (0 or the reentrant count).
Example (Counting write locks)
import { Effect, TxReentrantLock } from "effect"
const program = Effect.gen(function*() {
const lock = yield* TxReentrantLock.make()
const count = yield* TxReentrantLock.writeLocks(lock)
console.log(count) // 0
})
writeLocks = (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<number> =>
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 OptionOption.isSome(const state: anyconst state: {
readers: HashMap.HashMap<number, number>;
writer: Option.Option<readonly [fiberId: number, count: number]>;
}
state.writer) ? const state: anyconst state: {
readers: HashMap.HashMap<number, number>;
writer: Option.Option<readonly [fiberId: number, count: number]>;
}
state.writer.value[1] : 0
})