public static async ValueTask ConsumeEnumerator <T>(this IAsyncEnumerator <T> enumerator)
 {
     await using var en = enumerator.ConfigureAwait(false);
     while (await enumerator.MoveNextAsync().ConfigureAwait(false))
     {
         ;
     }
 }
Example #2
0
 private static async Task AwaitMoveNextAsyncAndDispose <T>(Task <bool> moveNextAsync, IAsyncEnumerator <T> enumerator)
 {
     if (enumerator != null)
     {
         await using (enumerator.ConfigureAwait(false))
         {
             if (moveNextAsync != null)
             {
                 await moveNextAsync.ConfigureAwait(false);
             }
         }
     }
 }
    public static async IAsyncEnumerator <int> SimulateProcessing(this IAsyncEnumerator <int> enumerator, int procesingFrequency, TimeSpan processingLength)
    {
        await using var en = enumerator.ConfigureAwait(false);

        int count = 0;

        while (await enumerator.MoveNextAsync().ConfigureAwait(false))
        {
            if (++count == procesingFrequency)
            {
                count = 0;
                Thread.Sleep(processingLength);
            }
            yield return(enumerator.Current + 1);
        }
    }
Example #4
0
 private static async Task AwaitMoveNextAsyncAndDispose <T>(Task <bool>?moveNextAsync, IAsyncEnumerator <T>?enumerator)
 {
     if (enumerator != null)
     {
         await using (enumerator.ConfigureAwait(false))
         {
             if (moveNextAsync != null)
             {
                 try
                 {
                     await moveNextAsync.ConfigureAwait(false);
                 }
                 catch (TaskCanceledException)
                 {
                     // ignored because of cancelling the non-winners
                 }
             }
         }
     }
 }