Class AsyncTrigger
Represents asynchronous trigger which allows to resume suspended callers based on registered conditions.
Inherited Members
Namespace: DotNext.Threading
Assembly: DotNext.Threading.dll
Syntax
public class AsyncTrigger : QueuedSynchronizer, IAsyncEvent, ISynchronizer, IDisposable
Methods
| Improve this Doc View SourceSignal()
Signals to all suspended callers that do not rely on state.
Declaration
public void Signal()
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This trigger has been disposed. |
Signal<TState>(TState)
Signals to all suspended callers about the new state.
Declaration
public void Signal<TState>(TState state)
where TState : class
Parameters
Type | Name | Description |
---|---|---|
TState | state | The new state of the trigger. |
Type Parameters
Name | Description |
---|---|
TState | The type of the state maintained externally. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This trigger has been disposed. |
Signal<TState>(TState, Action<TState>)
Signals to all suspended callers about the new state.
Declaration
public void Signal<TState>(TState state, Action<TState> mutator)
where TState : class
Parameters
Type | Name | Description |
---|---|---|
TState | state | The state to be modified. |
Action<TState> | mutator | State mutation. |
Type Parameters
Name | Description |
---|---|
TState | The type of the state maintained externally. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This trigger has been disposed. |
Signal<TState, TArgs>(TState, Action<TState, TArgs>, TArgs)
Signals to all suspended callers about the new state.
Declaration
public void Signal<TState, TArgs>(TState state, Action<TState, TArgs> mutator, TArgs args)
where TState : class
Parameters
Type | Name | Description |
---|---|---|
TState | state | The state to be modified. |
Action<TState, TArgs> | mutator | State mutation. |
TArgs | args | The arguments to be passed to the mutator. |
Type Parameters
Name | Description |
---|---|
TState | The type of the state maintained externally. |
TArgs | The type of the arguments of state mutator. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This trigger has been disposed. |
SignalAndWaitAsync(CancellationToken)
Signals to all suspended callers and waits for the signal.
Declaration
public Task SignalAndWaitAsync(CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
Task | The task representing asynchronous execution of this method. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This trigger has been disposed. |
OperationCanceledException | The operation has been canceled. |
SignalAndWaitAsync(TimeSpan, CancellationToken)
Signals to all suspended callers and waits for the signal.
Declaration
public Task<bool> SignalAndWaitAsync(TimeSpan timeout, CancellationToken token = default(CancellationToken))
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 |
---|---|
Task<Boolean> | 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. |
SignalAndWaitAsync<TState>(TState, Action<TState>, Predicate<TState>, CancellationToken)
Signals to all suspended callers and waits for the event that meets to the specified condition atomically.
Declaration
public Task SignalAndWaitAsync<TState>(TState state, Action<TState> mutator, Predicate<TState> condition, CancellationToken token = default(CancellationToken))
where TState : class
Parameters
Type | Name | Description |
---|---|---|
TState | state | The state to be inspected by predicate. |
Action<TState> | mutator | State mutation action. |
Predicate<TState> | condition | The condition to wait for. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
Task | The task representing asynchronous execution of this method. |
Type Parameters
Name | Description |
---|---|
TState | The type of the state to be inspected. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This trigger has been disposed. |
OperationCanceledException | The operation has been canceled. |
SignalAndWaitAsync<TState>(TState, Action<TState>, Predicate<TState>, TimeSpan, CancellationToken)
Signals to all suspended callers and waits for the event that meets to the specified condition atomically.
Declaration
public Task<bool> SignalAndWaitAsync<TState>(TState state, Action<TState> mutator, Predicate<TState> condition, TimeSpan timeout, CancellationToken token = default(CancellationToken))
where TState : class
Parameters
Type | Name | Description |
---|---|---|
TState | state | The state to be inspected by predicate. |
Action<TState> | mutator | State mutation action. |
Predicate<TState> | condition | The condition to wait for. |
TimeSpan | timeout | The time to wait for the signal. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
Task<Boolean> | true if event is triggered in timely manner; false if timeout occurred. |
Type Parameters
Name | Description |
---|---|
TState | The type of the state to be inspected. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This trigger has been disposed. |
OperationCanceledException | The operation has been canceled. |
SignalAndWaitAsync<TState>(TState, Predicate<TState>, CancellationToken)
Signals to all suspended callers and waits for the event that meets to the specified condition atomically.
Declaration
public Task SignalAndWaitAsync<TState>(TState state, Predicate<TState> condition, CancellationToken token = default(CancellationToken))
where TState : class
Parameters
Type | Name | Description |
---|---|---|
TState | state | The state to be inspected by predicate. |
Predicate<TState> | condition | The condition to wait for. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
Task | The task representing asynchronous execution of this method. |
Type Parameters
Name | Description |
---|---|
TState | The type of the state to be inspected. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This trigger has been disposed. |
OperationCanceledException | The operation has been canceled. |
SignalAndWaitAsync<TState>(TState, Predicate<TState>, TimeSpan, CancellationToken)
Signals to all suspended callers and waits for the event that meets to the specified condition atomically.
Declaration
public Task<bool> SignalAndWaitAsync<TState>(TState state, Predicate<TState> condition, TimeSpan timeout, CancellationToken token = default(CancellationToken))
where TState : class
Parameters
Type | Name | Description |
---|---|---|
TState | state | The state to be inspected by predicate. |
Predicate<TState> | condition | The condition to wait for. |
TimeSpan | timeout | The time to wait for the signal. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
Task<Boolean> | true if event is triggered in timely manner; false if timeout occurred. |
Type Parameters
Name | Description |
---|---|
TState | The type of the state to be inspected. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This trigger has been disposed. |
OperationCanceledException | The operation has been canceled. |
SignalAndWaitAsync<TState, TArgs>(TState, Action<TState, TArgs>, TArgs, Predicate<TState>, CancellationToken)
Signals to all suspended callers and waits for the event that meets to the specified condition atomically.
Declaration
public Task SignalAndWaitAsync<TState, TArgs>(TState state, Action<TState, TArgs> mutator, TArgs args, Predicate<TState> condition, CancellationToken token = default(CancellationToken))
where TState : class
Parameters
Type | Name | Description |
---|---|---|
TState | state | The state to be inspected by predicate. |
Action<TState, TArgs> | mutator | State mutation action. |
TArgs | args | The arguments to be passed to the action. |
Predicate<TState> | condition | The condition to wait for. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
Task | The task representing asynchronous execution of this method. |
Type Parameters
Name | Description |
---|---|
TState | The type of the state to be inspected. |
TArgs | The type of the arguments of mutation action. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This trigger has been disposed. |
OperationCanceledException | The operation has been canceled. |
SignalAndWaitAsync<TState, TArgs>(TState, Action<TState, TArgs>, TArgs, Predicate<TState>, TimeSpan, CancellationToken)
Signals to all suspended callers and waits for the event that meets to the specified condition atomically.
Declaration
public Task<bool> SignalAndWaitAsync<TState, TArgs>(TState state, Action<TState, TArgs> mutator, TArgs args, Predicate<TState> condition, TimeSpan timeout, CancellationToken token = default(CancellationToken))
where TState : class
Parameters
Type | Name | Description |
---|---|---|
TState | state | The state to be inspected by predicate. |
Action<TState, TArgs> | mutator | State mutation action. |
TArgs | args | The arguments to be passed to the action. |
Predicate<TState> | condition | The condition to wait for. |
TimeSpan | timeout | The time to wait for the signal. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
Task<Boolean> | true if event is triggered in timely manner; false if timeout occurred. |
Type Parameters
Name | Description |
---|---|
TState | The type of the state to be inspected. |
TArgs | The type of the arguments of mutation action. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This trigger has been disposed. |
OperationCanceledException | The operation has been canceled. |
WaitAsync(TimeSpan, CancellationToken)
Suspends the caller and waits for the signal.
Declaration
public Task<bool> WaitAsync(TimeSpan timeout, CancellationToken token = default(CancellationToken))
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 |
---|---|
Task<Boolean> | 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
| Improve this Doc View SourceWaitAsync<TState>(TState, Predicate<TState>, CancellationToken)
Suspends the caller and waits for the event that meets to the specified condition.
Declaration
public Task WaitAsync<TState>(TState state, Predicate<TState> condition, CancellationToken token = default(CancellationToken))
where TState : class
Parameters
Type | Name | Description |
---|---|---|
TState | state | The state to be inspected by predicate. |
Predicate<TState> | condition | The condition to wait for. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
Task | true if event is triggered in timely manner; false if timeout occurred. |
Type Parameters
Name | Description |
---|---|
TState | The type of the state to be inspected. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This trigger has been disposed. |
OperationCanceledException | The operation has been canceled. |
WaitAsync<TState>(TState, Predicate<TState>, TimeSpan, CancellationToken)
Suspends the caller and waits for the event that meets to the specified condition.
Declaration
public Task<bool> WaitAsync<TState>(TState state, Predicate<TState> condition, TimeSpan timeout, CancellationToken token = default(CancellationToken))
where TState : class
Parameters
Type | Name | Description |
---|---|---|
TState | state | The state to be inspected by predicate. |
Predicate<TState> | condition | The condition to wait for. |
TimeSpan | timeout | The time to wait for the signal. |
CancellationToken | token | The token that can be used to cancel the operation. |
Returns
Type | Description |
---|---|
Task<Boolean> | true if event is triggered in timely manner; false if timeout occurred. |
Type Parameters
Name | Description |
---|---|
TState | The type of the state to be inspected. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | This trigger has been disposed. |
OperationCanceledException | The operation has been canceled. |
Explicit Interface Implementations
| Improve this Doc View SourceIAsyncEvent.IsSet
Declaration
bool IAsyncEvent.IsSet { get; }
Returns
Type | Description |
---|---|
Boolean |
IAsyncEvent.Reset()
Declaration
bool IAsyncEvent.Reset()
Returns
Type | Description |
---|---|
Boolean |
IAsyncEvent.Signal()
Declaration
bool IAsyncEvent.Signal()
Returns
Type | Description |
---|---|
Boolean |