Hyperlinkv0.8.0-beta.28

TxReentrantLock

TxReentrantLock.readLockconsteffect/TxReentrantLock.ts:349
(self: TxReentrantLock): Effect.Effect<number, never, Scope.Scope>

Acquires a read lock for the duration of the scope. The lock is automatically released when the scope closes.

Example (Holding a scoped read lock)

import { Effect, TxReentrantLock } from "effect"

const program = Effect.gen(function*() {
  const lock = yield* TxReentrantLock.make()

  yield* Effect.scoped(
    Effect.gen(function*() {
      yield* TxReentrantLock.readLock(lock)
      // read lock is held for the duration of the scope
    })
  )
  // read lock is released
})
mutations
export const readLock = (self: TxReentrantLock): Effect.Effect<number, never, Scope.Scope> =>
  Effect.acquireRelease(
    acquireRead(self),
    () => releaseRead(self)
  )