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(); }
Task IChannelReader <TOutput> .WaitToReadAsync(CancellationToken token) => readTrigger.WaitAsync(token);
/// <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);
/// <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);
/// <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);