daniellansun commented on PR #2987:
URL: https://github.com/apache/groovy/pull/2987#issuecomment-6250559176

   Current solution borrows ideas from C#:
   ```C#
   using System.Threading.Channels;
   
   var channel = Channel.CreateBounded<int>(2);
   
   _ = Task.Run(async () =>
   {
       try
       {
           for (var i = 1; i <= 3; i++)
           {
               if (i == 3)
                   throw new InvalidOperationException("sensor failed");
               await channel.Writer.WriteAsync(i * i);
           }
           channel.Writer.Complete();
       }
       catch (Exception failure)
       {
           channel.Writer.Complete(failure);
       }
   });
   
   var seen = new List<int>();
   try
   {
       await foreach (var value in channel.Reader.ReadAllAsync())
           seen.Add(value);
   }
   catch (InvalidOperationException e)
   {
       Console.WriteLine(e.Message); // sensor failed
   }
   
   // seen == [1, 4]
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to