I am trying to achieve a supplier and consumer pattern where I am calling 4 simultaneous external APIs in parallel and adding the results to a non-blocking collection and running a CPU-intensive task which watches results in the non-blocking collection, does a calculation as each result comes in and moves the results to another collection. Pseudo-code:
Task task1 = CallApiAndMoveToCollectionResult1();
Task task2 = CallApiAndMoveToCollectionResult1();
Task task3 = CallApiAndMoveToCollectionResult1();
Task task4 = CallApiAndMoveToCollectionResult1();
await Task.WhenAll(task1,task2,task3,task4);
WatchCollectionAndCalculateBatches();
How can I run synchronous WatchCollectionAndCalculateBatches() at the same time as await Task.WhenAll(task1,task2,task3,task4) which is asynchronous?