Core.ToTask - Dmitry-Bychenko/Amphisbaena GitHub Wiki

ToTask

Ends execution without computation and converts ChannelReader to Task ready for await:

Declaration (has overloads)

public static async Task ToTask<T>(this ChannelReader<T> reader, 
                                        ChannelParallelOptions options) 

Example

using Amphisbaena;
using Amphisbaena.Linq;

...

int[] data = new int[] {1, 2, 3, -3, 4, -1, 2};

// Here we do all the work in `ActForEach`; and then complete execution with ToTask:
await data
  .ToChannelReader()
  .ActForEach((item, index) => Console.WriteLine($"Negative value {item} at {index}"),
              (item, index) => item < 0)
  .ToTask();