// Async entry point public static async Task MainAsync() { var receiver = new RecordReceiver(); // I'll provide a few records: // - a delay big enough between the 1st and the 2nd such that the 1st will be dispatched // - 8 records in a row, such that 5 of them will be dispatched, and 3 of them will wait // - again, a delay big enough that will provoke the last 3 records to be dispatched // - and a final record, which will wait to be dispatched // // We await for Task.Delay between providing records, // but we'll await for the records in the end only // // That is, we'll not await each record before the next, // as that would mean each record would only be dispatched after at least the timeout var t1 = receiver.ReceiveAsync(new Record(1)); await Task.Delay(TimeSpan.FromMilliseconds(300)); var t2 = receiver.ReceiveAsync(new Record(2)); var t3 = receiver.ReceiveAsync(new Record(3)); var t4 = receiver.ReceiveAsync(new Record(4)); var t5 = receiver.ReceiveAsync(new Record(5)); var t6 = receiver.ReceiveAsync(new Record(6)); var t7 = receiver.ReceiveAsync(new Record(7)); var t8 = receiver.ReceiveAsync(new Record(8)); var t9 = receiver.ReceiveAsync(new Record(9)); await Task.Delay(TimeSpan.FromMilliseconds(300)); var t10 = receiver.ReceiveAsync(new Record(10)); // I probably should have used a list of records, but this is just an example await Task.WhenAll(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10); }
public static async Task MainAsync() { var receiver = new RecordReceiver(); var t1 = receiver.ReceiveAsync(new Record(1)); await Task.Delay(TimeSpan.FromMilliseconds(300)); var t2 = receiver.ReceiveAsync(new Record(2)); var t3 = receiver.ReceiveAsync(new Record(3)); var t4 = receiver.ReceiveAsync(new Record(4)); var t5 = receiver.ReceiveAsync(new Record(5)); var t6 = receiver.ReceiveAsync(new Record(6)); var t7 = receiver.ReceiveAsync(new Record(7)); var t8 = receiver.ReceiveAsync(new Record(8)); var t9 = receiver.ReceiveAsync(new Record(9)); await Task.Delay(TimeSpan.FromMilliseconds(300)); var t10 = receiver.ReceiveAsync(new Record(10)); await Task.WhenAll(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10); }