Show / Hide Table of Contents

Class AsyncTrigger

Represents asynchronous trigger that allows to resume and suspend concurrent flows.

Inheritance
object
Disposable
QueuedSynchronizer
AsyncTrigger
Implements
IAsyncEvent
IDisposable
IResettable
Inherited Members
QueuedSynchronizer.MeasurementTags
QueuedSynchronizer.TrackSuspendedCallers(Func<object>)
QueuedSynchronizer.SetCallerInformation(object)
QueuedSynchronizer.GetSuspendedCallers()
QueuedSynchronizer.CancelSuspendedCallers(CancellationToken)
QueuedSynchronizer.Dispose(bool)
QueuedSynchronizer.Dispose(Exception)
QueuedSynchronizer.DisposeAsyncCore()
QueuedSynchronizer.DisposeAsync()
Disposable.IsDisposed
Disposable.IsDisposing
Disposable.IsDisposingOrDisposed
Disposable.CreateException()
Disposable.DisposedTask
Disposable.GetDisposedTask<T>()
Disposable.TrySetDisposedException<T>(TaskCompletionSource<T>)
Disposable.TrySetDisposedException(TaskCompletionSource)
Disposable.TryBeginDispose()
Disposable.Dispose()
Disposable.Dispose(IEnumerable<IDisposable>)
Disposable.DisposeAsync(IEnumerable<IAsyncDisposable>)
Disposable.Dispose<T>(ReadOnlySpan<T>)
Disposable.DisposeAsync(params IAsyncDisposable[])
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public class AsyncTrigger : QueuedSynchronizer, IAsyncEvent, IDisposable, IResettable

Constructors

| Edit this page View Source

AsyncTrigger()

Initializes a new trigger.

Declaration
public AsyncTrigger()
| Edit this page View Source

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

concurrencyLevel is less than or equal to zero.

Methods

| Edit this page View Source

Signal(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.

| Edit this page View Source

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

throwOnEmptyQueue is true and no suspended callers in the queue.

| Edit this page View Source

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

throwOnEmptyQueue is true and no suspended callers in the queue.

| Edit this page View Source

SpinWaitAsync<TCondition>(TCondition, CancellationToken)

Suspends the caller until this event is set.

Declaration
public ValueTask SpinWaitAsync<TCondition>(TCondition condition, CancellationToken token = default) where TCondition : 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

true, if this event was set; otherwise, false.

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

condition is null.

ObjectDisposedException

The current instance has already been disposed.

OperationCanceledException

The operation has been canceled.

| Edit this page View Source

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 : 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>

true, if this event was set; otherwise, false.

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

condition is null.

ObjectDisposedException

The current instance has already been disposed.

ArgumentOutOfRangeException

timeout is negative.

OperationCanceledException

The operation has been canceled.

| Edit this page View Source

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
Signal(bool)
| Edit this page View Source

WaitAsync(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.

See Also
Signal(bool)

Implements

IAsyncEvent
IDisposable
IResettable

Extension Methods

BasicExtensions.As<T>(T)
BasicExtensions.GetUserData<T>(T)
BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, ReadOnlySpan<T>)
ExpressionBuilder.Const<T>(T)
AsyncLockAcquisition.AcquireLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireLockAsync<T>(T, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireReadLockAsync<T>(T, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, bool, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, bool, TimeSpan, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, CancellationToken)
AsyncLockAcquisition.AcquireWriteLockAsync<T>(T, TimeSpan, CancellationToken)
LockAcquisition.AcquireReadLock<T>(T)
LockAcquisition.AcquireReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireUpgradeableReadLock<T>(T)
LockAcquisition.AcquireUpgradeableReadLock<T>(T, TimeSpan)
LockAcquisition.AcquireWriteLock<T>(T)
LockAcquisition.AcquireWriteLock<T>(T, TimeSpan)
  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾