Hyperlinkv0.8.0-beta.28

TxReentrantLock

TxReentrantLock.writeLocksconsteffect/TxReentrantLock.ts:555
(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
export const writeLocks = (self: TxReentrantLock): Effect.Effect<number> =>
  Effect.gen(function*() {
    const state = yield* TxRef.get(self.stateRef)
    return Option.isSome(state.writer) ? state.writer.value[1] : 0
  })