Skip to main content Link Search Menu Expand Document (external link)

TReentrantLock overview

Added in v2.0.0


Table of contents


constructors

make

Makes a new reentrant read/write lock.

Signature

export declare const make: STM.STM<TReentrantLock, never, never>

Added in v2.0.0

models

TReentrantLock (interface)

A TReentrantLock is a reentrant read/write lock. Multiple readers may all concurrently acquire read locks. Only one writer is allowed to acquire a write lock at any given time. Read locks may be upgraded into write locks. A fiber that has a write lock may acquire other write locks or read locks.

The two primary methods of this structure are readLock, which acquires a read lock in a scoped context, and writeLock, which acquires a write lock in a scoped context.

Although located in the STM package, there is no need for locks within STM transactions. However, this lock can be quite useful in effectful code, to provide consistent read/write access to mutable state; and being in STM allows this structure to be composed into more complicated concurrent structures that are consumed from effectful code.

Signature

export interface TReentrantLock extends TReentrantLock.Proto {}

Added in v2.0.0

mutations

acquireRead

Acquires a read lock. The transaction will suspend until no other fiber is holding a write lock. Succeeds with the number of read locks held by this fiber.

Signature

export declare const acquireRead: (self: TReentrantLock) => STM.STM<number>

Added in v2.0.0

acquireWrite

Acquires a write lock. The transaction will suspend until no other fibers are holding read or write locks. Succeeds with the number of write locks held by this fiber.

Signature

export declare const acquireWrite: (self: TReentrantLock) => STM.STM<number>

Added in v2.0.0

fiberReadLocks

Retrieves the number of acquired read locks for this fiber.

Signature

export declare const fiberReadLocks: (self: TReentrantLock) => STM.STM<number>

Added in v2.0.0

fiberWriteLocks

Retrieves the number of acquired write locks for this fiber.

Signature

export declare const fiberWriteLocks: (self: TReentrantLock) => STM.STM<number>

Added in v2.0.0

lock

Just a convenience method for applications that only need reentrant locks, without needing a distinction between readers / writers.

See TReentrantLock.writeLock.

Signature

export declare const lock: (self: TReentrantLock) => Effect.Effect<number, never, Scope.Scope>

Added in v2.0.0

locked

Determines if any fiber has a read or write lock.

Signature

export declare const locked: (self: TReentrantLock) => STM.STM<boolean>

Added in v2.0.0

readLock

Obtains a read lock in a scoped context.

Signature

export declare const readLock: (self: TReentrantLock) => Effect.Effect<number, never, Scope.Scope>

Added in v2.0.0

readLocked

Determines if any fiber has a read lock.

Signature

export declare const readLocked: (self: TReentrantLock) => STM.STM<boolean>

Added in v2.0.0

readLocks

Retrieves the total number of acquired read locks.

Signature

export declare const readLocks: (self: TReentrantLock) => STM.STM<number>

Added in v2.0.0

releaseRead

Releases a read lock held by this fiber. Succeeds with the outstanding number of read locks held by this fiber.

Signature

export declare const releaseRead: (self: TReentrantLock) => STM.STM<number>

Added in v2.0.0

releaseWrite

Releases a write lock held by this fiber. Succeeds with the outstanding number of write locks held by this fiber.

Signature

export declare const releaseWrite: (self: TReentrantLock) => STM.STM<number>

Added in v2.0.0

withLock

Runs the specified workflow with a lock.

Signature

export declare const withLock: {
  (self: TReentrantLock): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
  <A, E, R>(effect: Effect.Effect<A, E, R>, self: TReentrantLock): Effect.Effect<A, E, R>
}

Added in v2.0.0

withReadLock

Runs the specified workflow with a read lock.

Signature

export declare const withReadLock: {
  (self: TReentrantLock): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
  <A, E, R>(effect: Effect.Effect<A, E, R>, self: TReentrantLock): Effect.Effect<A, E, R>
}

Added in v2.0.0

withWriteLock

Runs the specified workflow with a write lock.

Signature

export declare const withWriteLock: {
  (self: TReentrantLock): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
  <A, E, R>(effect: Effect.Effect<A, E, R>, self: TReentrantLock): Effect.Effect<A, E, R>
}

Added in v2.0.0

writeLock

Obtains a write lock in a scoped context.

Signature

export declare const writeLock: (self: TReentrantLock) => Effect.Effect<number, never, Scope.Scope>

Added in v2.0.0

writeLocked

Determines if a write lock is held by some fiber.

Signature

export declare const writeLocked: (self: TReentrantLock) => STM.STM<boolean>

Added in v2.0.0

writeLocks

Computes the number of write locks held by fibers.

Signature

export declare const writeLocks: (self: TReentrantLock) => STM.STM<number>

Added in v2.0.0

symbols

TReentrantLockTypeId

Signature

export declare const TReentrantLockTypeId: typeof TReentrantLockTypeId

Added in v2.0.0

TReentrantLockTypeId (type alias)

Signature

export type TReentrantLockTypeId = typeof TReentrantLockTypeId

Added in v2.0.0

utils

TReentrantLock (namespace)

Added in v2.0.0

Proto (interface)

Signature

export interface Proto {
  readonly [TReentrantLockTypeId]: TReentrantLockTypeId
}

Added in v2.0.0