<PackageReference Include="Nito.AsyncEx.Coordination" Version="5.0.0" />

Nito.AsyncEx.AsyncSemaphore

public sealed class AsyncSemaphore
An async-compatible semaphore. Alternatively, you could use SemaphoreSlim.
public long CurrentCount { get; }

Gets the number of slots currently available on this semaphore. This member is seldom used; code using this member has a high possibility of race conditions.

public int Id { get; }

Gets a semi-unique identifier for this asynchronous semaphore.

public AsyncSemaphore(long initialCount)

Creates a new async-compatible semaphore with the specified initial count.

public IDisposable Lock(CancellationToken cancellationToken)

Synchronously waits on the semaphore, and returns a disposable that releases the semaphore when disposed, thus treating this semaphore as a "multi-lock".

public IDisposable Lock()

Synchronously waits on the semaphore, and returns a disposable that releases the semaphore when disposed, thus treating this semaphore as a "multi-lock".

public AwaitableDisposable<IDisposable> LockAsync(CancellationToken cancellationToken)

Asynchronously waits on the semaphore, and returns a disposable that releases the semaphore when disposed, thus treating this semaphore as a "multi-lock".

public AwaitableDisposable<IDisposable> LockAsync()

Asynchronously waits on the semaphore, and returns a disposable that releases the semaphore when disposed, thus treating this semaphore as a "multi-lock".

public void Release(long releaseCount)

Releases the semaphore.

public void Release()

Releases the semaphore.

public void Wait(CancellationToken cancellationToken)

Synchronously waits for a slot in the semaphore to be available. This method may block the calling thread.

public void Wait()

Synchronously waits for a slot in the semaphore to be available. This method may block the calling thread.

public Task WaitAsync(CancellationToken cancellationToken)

Asynchronously waits for a slot in the semaphore to be available.

public Task WaitAsync()

Asynchronously waits for a slot in the semaphore to be available.