Hyperlinkv0.8.0-beta.28

TxReentrantLock

TxReentrantLock.lockedconsteffect/TxReentrantLock.ts:579
(self: TxReentrantLock): Effect.Effect<boolean>

Checks whether the lock is held by any fiber (read or write).

Example (Checking whether a lock is held)

import { Effect, TxReentrantLock } from "effect"

const program = Effect.gen(function*() {
  const lock = yield* TxReentrantLock.make()
  const isLocked = yield* TxReentrantLock.locked(lock)
  console.log(isLocked) // false
})
getters
export const locked = (self: TxReentrantLock): Effect.Effect<boolean> =>
  Effect.gen(function*() {
    const state = yield* TxRef.get(self.stateRef)
    return HashMap.size(state.readers) > 0 || Option.isSome(state.writer)
  })