Esempio n. 1
0
 private static async Task ReadAsyncStream(IAsyncEnumerable <bool> stream, int streamIndex)
 {
     try
     {
         await foreach (var input in stream)
         {
             var value = Convert.ToInt32(input);
             //Console.WriteLine($"We got {value} for {streamIndex}");
             var isStreamSaved = SavedStreams.TryGetValue(streamIndex, out _);
             if (isStreamSaved)
             {
                 SavedStreams.AddOrUpdate(streamIndex, -1, (index, oldValue) => oldValue * (1 - C) + value);
                 SavedStreams.TryGetValue(streamIndex, out double updatedSum);
                 if (updatedSum < 0.5)
                 {
                     SavedStreams.TryRemove(streamIndex, out _);
                 }
             }
             else if (value == 1)
             {
                 SavedStreams.AddOrUpdate(streamIndex, 1, (index, oldValue) => 1);
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine($"{streamIndex}, {ex.Message}");
     }
 }