(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
Source effect/TxReentrantLock.ts:3495 lines
export const const readLock: (
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
})
readLock = (self: TxReentrantLock(parameter) self: {
stateRef: TxRef.TxRef<LockState>;
toString: () => string;
toJSON: () => unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self: TxReentrantLock): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<number, never, import ScopeScope.type Scope.Scope = /*unresolved*/ anyScope> =>
import EffectEffect.acquireRelease(
const acquireRead: (
self: TxReentrantLock
) => Effect.Effect<number>
Acquires a read lock. Blocks if another fiber holds the write lock.
If the current fiber already holds the write lock, the read lock is granted (reentrancy).
Returns the current number of read locks held by this fiber.
Example (Acquiring a read lock)
import { Effect, TxReentrantLock } from "effect"
const program = Effect.gen(function*() {
const lock = yield* TxReentrantLock.make()
const count = yield* TxReentrantLock.acquireRead(lock)
console.log(count) // 1
yield* TxReentrantLock.releaseRead(lock)
})
acquireRead(self: TxReentrantLock(parameter) self: {
stateRef: TxRef.TxRef<LockState>;
toString: () => string;
toJSON: () => unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self),
() => const releaseRead: (
self: TxReentrantLock
) => Effect.Effect<number>
Releases one read lock held by the current fiber.
When to use
Use to leave a manually acquired read lock.
Details
Returns the remaining number of read locks held by this fiber.
Example (Releasing a read lock)
import { Effect, TxReentrantLock } from "effect"
const program = Effect.gen(function*() {
const lock = yield* TxReentrantLock.make()
yield* TxReentrantLock.acquireRead(lock)
const remaining = yield* TxReentrantLock.releaseRead(lock)
console.log(remaining) // 0
})
releaseRead(self: TxReentrantLock(parameter) self: {
stateRef: TxRef.TxRef<LockState>;
toString: () => string;
toJSON: () => unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
self)
)