using System.Reactive.Linq;
using System.Threading.Tasks;
public static async Task Main()
var sequence = Observable
.Create<int>(async (observer, ct) =>
await Task.Delay(500, ct);
observer.OnError(new Exception());
.Select(x => Observable.FromAsync(async (ct) =>
Console.WriteLine($"Item {x} started");
try { await Task.Delay(1000, ct); }
catch (OperationCanceledException) { Console.WriteLine($"Item {x} aborted"); throw; }
Console.WriteLine($"Item {x} finished");
.Do(x => Console.WriteLine($"Received: {x}"));
try { await sequence.DefaultIfEmpty(); }
catch (Exception ex) { Console.WriteLine($"Await failed ({ex.Message})"); }