Ejemplo n.º 1
0
 private static async Task Track(TimeSpan timeout, IAsyncEvent refreshEvent, Action candidateState, CancellationToken token)
 {
     //spin loop to wait for the timeout
     while (await refreshEvent.WaitAsync(timeout, token).ConfigureAwait(false))
     {
     }
     //timeout happened, move to candidate state
     candidateState();
 }
        private static async Task Track(TimeSpan timeout, IAsyncEvent refreshEvent, Action candidateState, params CancellationToken[] tokens)
        {
            using var tokenSource = CancellationTokenSource.CreateLinkedTokenSource(tokens);

            // spin loop to wait for the timeout
            while (await refreshEvent.WaitAsync(timeout, tokenSource.Token).ConfigureAwait(false))
            {
            }

            // timeout happened, move to candidate state
            candidateState();
        }
Ejemplo n.º 3
0
 Task IChannelReader <TOutput> .WaitToReadAsync(CancellationToken token) => readTrigger.WaitAsync(token);
Ejemplo n.º 4
0
 /// <summary>
 /// Turns caller into idle state until the current event is set. 
 /// </summary>
 /// <remarks>
 /// This method can potentially blocks execution of async flow infinitely.
 /// </remarks>
 /// <param name="event">An event to synchronize with.</param>
 /// <returns>A promise of signaled state.</returns>
 public static Task WaitAsync(this IAsyncEvent @event) => @event.WaitAsync(CancellationToken.None);
Ejemplo n.º 5
0
 /// <summary>
 /// Turns caller into idle state until the current event is set. 
 /// </summary>
 /// <remarks>
 /// This method can potentially blocks execution of async flow infinitely.
 /// </remarks>
 /// <param name="event">An event to synchronize with.</param>
 /// <param name="token">The token that can be used to abort wait process.</param>
 /// <returns>A promise of signaled state.</returns>
 public static Task WaitAsync(this IAsyncEvent @event, CancellationToken token) => @event.WaitAsync(InfiniteTimeSpan, token);
Ejemplo n.º 6
0
 /// <summary>
 /// Turns caller into idle state until the current event is set. 
 /// </summary>
 /// <param name="event">An event to synchronize with.</param>
 /// <param name="timeout">The interval to wait for the signaled state.</param>
 /// <returns><see langword="true"/> if signaled state was set; otherwise, <see langword="false"/>.</returns>
 public static Task<bool> WaitAsync(this IAsyncEvent @event, TimeSpan timeout) => @event.WaitAsync(timeout, CancellationToken.None);