Class AsyncTrigger
Represents asynchronous trigger that allows to resume and suspend concurrent flows.
Inherited Members
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public class AsyncTrigger : QueuedSynchronizer, IAsyncEvent, IDisposable, IResettable
Constructors
| Edit this page View SourceAsyncTrigger()
Initializes a new trigger.
Declaration
public AsyncTrigger()
AsyncTrigger(int)
Initializes a new trigger.
Declaration
public AsyncTrigger(int concurrencyLevel)
Parameters
Type | Name | Description |
---|---|---|
int | concurrencyLevel | The expected number of concurrent flows. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
Methods
| Edit this page View SourceSignal(bool)
Resumes the first suspended caller in the wait queue.
Declaration
public bool Signal(bool resumeAll = false)
Parameters
Type | Name | Description |
---|---|---|
bool | resumeAll | true to resume all suspended callers in the queue; false to resume the first suspended caller in the queue. |
Returns
Type | Description |
---|---|
bool | true if at least one suspended caller has been resumed; otherwise, false. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This trigger has been disposed. |
SignalAndWaitAsync(bool, bool, CancellationToken)
Resumes the first suspended caller in the queue and suspends the immediate caller.
Declaration
public ValueTask SignalAndWaitAsync(bool resumeAll, bool throwOnEmptyQueue, CancellationToken token = default)
Parameters
Type | Name | Description |
---|---|---|
bool | resumeAll | true to resume all suspended callers in the queue; false to resume the first suspended caller in the queue. |
bool | throwOnEmptyQueue | true to throw InvalidOperationException if there is no suspended callers to resume; false to suspend the caller. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
ValueTask | The task representing asynchronous execution of this method. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This trigger has been disposed. |
OperationCanceledException | The operation has been canceled. |
InvalidOperationException |
|
SignalAndWaitAsync(bool, bool, TimeSpan, CancellationToken)
Resumes the first suspended caller in the queue and suspends the immediate caller.
Declaration
public ValueTask<bool> SignalAndWaitAsync(bool resumeAll, bool throwOnEmptyQueue, TimeSpan timeout, CancellationToken token = default)
Parameters
Type | Name | Description |
---|---|---|
bool | resumeAll | true to resume all suspended callers in the queue; false to resume the first suspended caller in the queue. |
bool | throwOnEmptyQueue | true to throw InvalidOperationException if there is no suspended callers to resume; false to suspend the caller. |
TimeSpan | timeout | The time to wait for the signal. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
ValueTask<bool> | true if event is triggered in timely manner; false if timeout occurred. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This trigger has been disposed. |
OperationCanceledException | The operation has been canceled. |
InvalidOperationException |
|
SpinWaitAsync<TCondition>(TCondition, CancellationToken)
Suspends the caller until this event is set.
Declaration
public ValueTask SpinWaitAsync<TCondition>(TCondition condition, CancellationToken token = default) where TCondition : notnull, ISupplier<bool>
Parameters
Type | Name | Description |
---|---|---|
TCondition | condition | Additional condition that must be checked before suspension. |
CancellationToken | token | The token that can be used to cancel waiting operation. |
Returns
Type | Description |
---|---|
ValueTask |
Type Parameters
Name | Description |
---|---|
TCondition | The type of predicate parameter. |
Remarks
If given predicate returns true then caller will not be suspended.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ObjectDisposedException | The current instance has already been disposed. |
OperationCanceledException | The operation has been canceled. |
SpinWaitAsync<TCondition>(TCondition, TimeSpan, CancellationToken)
Suspends the caller until this event is set.
Declaration
public ValueTask<bool> SpinWaitAsync<TCondition>(TCondition condition, TimeSpan timeout, CancellationToken token = default) where TCondition : notnull, ISupplier<bool>
Parameters
Type | Name | Description |
---|---|---|
TCondition | condition | Additional condition that must be checked before suspension. |
TimeSpan | timeout | The number of time to wait before this event is set. |
CancellationToken | token | The token that can be used to cancel waiting operation. |
Returns
Type | Description |
---|---|
ValueTask<bool> |
Type Parameters
Name | Description |
---|---|
TCondition | The type of predicate parameter. |
Remarks
If given predicate returns true then caller will not be suspended.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ObjectDisposedException | The current instance has already been disposed. |
ArgumentOutOfRangeException |
|
OperationCanceledException | The operation has been canceled. |
WaitAsync(CancellationToken)
Suspends the caller and waits for the signal.
Declaration
public ValueTask WaitAsync(CancellationToken token = default)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
ValueTask | The task representing asynchronous execution of this method. |
Remarks
This method always suspends the caller.
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This trigger has been disposed. |
OperationCanceledException | The operation has been canceled. |
See Also
| Edit this page View SourceWaitAsync(TimeSpan, CancellationToken)
Suspends the caller and waits for the signal.
Declaration
public ValueTask<bool> WaitAsync(TimeSpan timeout, CancellationToken token = default)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | timeout | The time to wait for the signal. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
ValueTask<bool> | true if event is triggered in timely manner; false if timeout occurred. |
Remarks
This method always suspends the caller.
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This trigger has been disposed. |
OperationCanceledException | The operation has been canceled. |