(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
})export const const writeLock: (
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
})
writeLock = (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 acquireWrite: (
self: TxReentrantLock
) => Effect.Effect<number>
Acquires the write lock for the current fiber.
When to use
Use to enter an exclusive section manually when withWriteLock is not the
right shape.
Details
Blocks if any other fiber holds a read or write lock. If the current fiber
already holds the write lock, the count is incremented. If the current fiber
holds a read lock, the write lock is granted as an upgrade.
Returns the current number of write locks held by this fiber.
Example (Acquiring a write lock)
import { Effect, TxReentrantLock } from "effect"
const program = Effect.gen(function*() {
const lock = yield* TxReentrantLock.make()
const count = yield* TxReentrantLock.acquireWrite(lock)
console.log(count) // 1
yield* TxReentrantLock.releaseWrite(lock)
})
acquireWrite(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 releaseWrite: (
self: TxReentrantLock
) => Effect.Effect<number>
Releases one write lock held by the current fiber.
When to use
Use to leave a manually acquired write lock.
Details
Returns the remaining number of write locks held by this fiber.
Example (Releasing a write lock)
import { Effect, TxReentrantLock } from "effect"
const program = Effect.gen(function*() {
const lock = yield* TxReentrantLock.make()
yield* TxReentrantLock.acquireWrite(lock)
const remaining = yield* TxReentrantLock.releaseWrite(lock)
console.log(remaining) // 0
})
releaseWrite(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)
)