Table of Contents

Class AsyncUsableLock

Namespace
Garyon.Mechanisms
Assembly
Garyon.dll

Represents an asynchronous lock that can be used in an async/await context without the lock statement.

public sealed class AsyncUsableLock
Inheritance
AsyncUsableLock
Inherited Members
Extension Methods

Properties

IsLocked

Determines whether the lock is currently locked.

public bool IsLocked { get; }

Property Value

bool

Methods

Lock()

Locks the current instance and returns a AsyncUsableLock.LockReleaser allowing the usage of the disposal pattern via using. If the lock is currently locked, this method will block until the lock is released from the current lock holder.

public AsyncUsableLock.LockReleaser Lock()

Returns

AsyncUsableLock.LockReleaser

A AsyncUsableLock.LockReleaser instance unlocking this instance once the releaser is disposed.

LockAsync()

Locks the current instance and returns a AsyncUsableLock.LockReleaser allowing the usage of the disposal pattern via using. If the lock is currently locked, this method will block until the lock is released from the current lock holder.

public Task<AsyncUsableLock.LockReleaser> LockAsync()

Returns

Task<AsyncUsableLock.LockReleaser>

A AsyncUsableLock.LockReleaser instance unlocking this instance once the releaser is disposed.

LockAsync(CancellationToken)

Locks the current instance and returns a AsyncUsableLock.LockReleaser allowing the usage of the disposal pattern via using. If the lock is currently locked, this method will block until the lock is released from the current lock holder.

public Task<AsyncUsableLock.LockReleaser> LockAsync(CancellationToken token)

Parameters

token CancellationToken

The CancellationToken that can cancel the wait from the lock to be released.

Returns

Task<AsyncUsableLock.LockReleaser>

A AsyncUsableLock.LockReleaser instance unlocking this instance once the releaser is disposed.

TryLock(out bool)

Attempts to lock the current lock, and immediately returns if already held.

public AsyncUsableLock.LockReleaser TryLock(out bool success)

Parameters

success bool

Returns true if this lock was successfully locked, otherwise false if the lock was already held.

Returns

AsyncUsableLock.LockReleaser

A AsyncUsableLock.LockReleaser instance unlocking this instance once the releaser is disposed, or default if the lock was already held. The default value can be simply ignored and left to be disposed for a no-op.

Unlock()

Unlocks the current instance. If the instance is not currently locked, this method will do nothing.

public void Unlock()