Hyperlinkv0.8.0-beta.28

TxReentrantLock

TxReentrantLock.writeLockconsteffect/TxReentrantLock.ts:380
(self: TxReentrantLock): Effect.Effect<number, never, Scope.Scope>

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

Example (Holding a scoped write lock)

import { Effect, TxReentrantLock } from "effect"

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

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