Table of Contents

Class AsyncSemaphore

Namespace
Arc4u.Threading
Assembly
Arc4u.Threading.dll

A minimal asynchronous semaphore: callers wait with WaitAsync() without blocking a thread and are served in first-in first-out order.

public class AsyncSemaphore
Inheritance
AsyncSemaphore
Inherited Members

Constructors

AsyncSemaphore(int)

Initializes a new instance of the AsyncSemaphore class.

public AsyncSemaphore(int initialCount)

Parameters

initialCount int

The number of callers that can enter without waiting.

Exceptions

ArgumentOutOfRangeException

initialCount is negative.

Methods

Release()

Releases the semaphore: the oldest waiter, if any, is resumed; otherwise the available count is incremented.

public void Release()

WaitAsync()

Asynchronously waits to enter the semaphore.

public Task WaitAsync()

Returns

Task

A task that is already completed when a slot is available; otherwise a task that completes when another caller calls Release().