Hyperlinkv0.8.0-beta.28

TxReentrantLock

TxReentrantLock.readLocksconsteffect/TxReentrantLock.ts:527
(self: TxReentrantLock): Effect.Effect<number>

Returns the total number of read locks held across all fibers.

Example (Counting read locks)

import { Effect, TxReentrantLock } from "effect"

const program = Effect.gen(function*() {
  const lock = yield* TxReentrantLock.make()
  yield* TxReentrantLock.acquireRead(lock)
  const count = yield* TxReentrantLock.readLocks(lock)
  console.log(count) // 1
  yield* TxReentrantLock.releaseRead(lock)
})
getters
export const readLocks = (self: TxReentrantLock): Effect.Effect<number> =>
  Effect.gen(function*() {
    const state = yield* TxRef.get(self.stateRef)
    let total = 0
    for (const [, count] of state.readers) {
      total += count
    }
    return total
  })