(): Effect.Effect<TxReentrantLock>Creates a new TxReentrantLock.
Example (Creating a reentrant lock)
import { Effect, TxReentrantLock } from "effect"
const program = Effect.gen(function*() {
const lock = yield* TxReentrantLock.make()
const isLocked = yield* TxReentrantLock.locked(lock)
console.log(isLocked) // false
})constructors
Source effect/TxReentrantLock.ts:1078 lines
export const const make: () => Effect.Effect<TxReentrantLock>Creates a new TxReentrantLock.
Example (Creating a reentrant lock)
import { Effect, TxReentrantLock } from "effect"
const program = Effect.gen(function*() {
const lock = yield* TxReentrantLock.make()
const isLocked = yield* TxReentrantLock.locked(lock)
console.log(isLocked) // false
})
make = (): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<TxReentrantLock> =>
import EffectEffect.gen(function*() {
const const stateRef: TxRef.TxRef<LockState>const stateRef: {
version: number;
pending: Map<unknown, () => void>;
value: A;
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; <…;
}
stateRef = yield* import TxRefTxRef.const make: <LockState>(
initial: LockState
) => any
Creates a new TxRef with the specified initial value.
When to use
Use to create a TxRef inside an Effect workflow.
Example (Creating transactional references)
import { Effect, TxRef } from "effect"
const program = Effect.gen(function*() {
// Create a transactional reference with initial value
const counter = yield* TxRef.make(0)
const name = yield* TxRef.make("Alice")
// Use in transactions
yield* Effect.tx(Effect.gen(function*() {
yield* TxRef.set(counter, 42)
yield* TxRef.set(name, "Bob")
}))
console.log(yield* TxRef.get(counter)) // 42
console.log(yield* TxRef.get(name)) // "Bob"
})
make<LockState>(const emptyState: LockStateconst emptyState: {
readers: HashMap.HashMap<number, number>;
writer: Option.Option<readonly [fiberId: number, count: number]>;
}
emptyState)
const const self: anyself = var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.create(o: object | null): any (+1 overload)Creates an object that has the specified prototype or that has null prototype.
create(const TxReentrantLockProto: Omit<
TxReentrantLock,
typeof TypeId | "stateRef"
>
TxReentrantLockProto)
const self: anyself[const TypeId: "~effect/transactions/TxReentrantLock"TypeId] = const TypeId: "~effect/transactions/TxReentrantLock"TypeId
const self: anyself.stateRef = const stateRef: TxRef.TxRef<LockState>const stateRef: {
version: number;
pending: Map<unknown, () => void>;
value: A;
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; <…;
}
stateRef
return const self: anyself
}).pipe(import EffectEffect.tx)