public static void SearchingWithCancellation() { Demo.DisplayHeader("Creating async observable with async-await and cancellation"); var exampleResetEvent = new AutoResetEvent(false); // Change the index to when you want the subscription disposed int cancelIndex = 1; var results = SearchEngineExample.Search_WithCancellation("Rx"); IDisposable subscription = Disposable.Empty; subscription = results .Select((result, index) => new { result, index }) //adding the item index to the notification .Do(x => { if (x.index == cancelIndex) { Console.WriteLine("Cancelling on index {0}", cancelIndex); subscription.Dispose(); exampleResetEvent.Set(); } }) .Select(x => x.result) //rollback the observable to be IObservable<string> .DoLast(() => exampleResetEvent.Set(), delay: TimeSpan.FromSeconds(1)) .SubscribeConsole("results"); exampleResetEvent.WaitOne(); }
public static void SearchingWithDefferedAsync() { Demo.DisplayHeader("Defferd async"); var results = SearchEngineExample.Search_DefferedConcatingTasks("Rx"); results.RunExample("defered"); }
public static void SearchingWithAsyncAwait() { Demo.DisplayHeader("Creating async observable with async-await"); var results = SearchEngineExample.Search_WithAsyncAwait("Rx"); results.RunExample("search async-await"); }
public static void SearchingWithConcatingTasks() { Demo.DisplayHeader("Converting Tasks to observables"); var results = SearchEngineExample.Search_ConcatingTasks("Rx"); results .RunExample("tasks to observables"); }