Table of Contents

Class AsyncMutex

Namespace
LfrlAnvil.Async
Assembly
LfrlAnvil.Core.dll

Represents a source of a fair asynchronous mutex primitive.

public sealed class AsyncMutex
Inheritance
AsyncMutex
Inherited Members
Extension Methods

Remarks

Lock is not reentrant.

Constructors

AsyncMutex()

Creates a new AsyncMutex instance.

public AsyncMutex()

Properties

Participants

Returns the total number of lock participants, which includes current lock holder and all waiters.

public int Participants { get; }

Property Value

int

Methods

EnterAsync(CancellationToken)

Asynchronously acquires an exclusive lock from this mutex.

public ValueTask<AsyncMutexLock> EnterAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Optional CancellationToken that can be used to cancel pending mutex acquisition.

Returns

ValueTask<AsyncMutexLock>

New ValueTask<TResult> instance which returns an AsyncMutexLock value.

Exceptions

OperationCanceledException

When provided cancellationToken was cancelled before the lock was acquired.

TrimExcess()

Attempts to discard unused resources.

public void TrimExcess()