Hyperlinkv0.8.0-beta.28

TxReentrantLock

TxReentrantLock.readLockedconsteffect/TxReentrantLock.ts:603
(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
export const readLocked = (self: TxReentrantLock): Effect.Effect<boolean> =>
  Effect.gen(function*() {
    const state = yield* TxRef.get(self.stateRef)
    return HashMap.size(state.readers) > 0
  })