예제 #1
0
        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();
        }
예제 #2
0
        public static void SearchingWithDefferedAsync()
        {
            Demo.DisplayHeader("Defferd async");

            var results = SearchEngineExample.Search_DefferedConcatingTasks("Rx");

            results.RunExample("defered");
        }
예제 #3
0
        public static void SearchingWithAsyncAwait()
        {
            Demo.DisplayHeader("Creating async observable with async-await");

            var results = SearchEngineExample.Search_WithAsyncAwait("Rx");

            results.RunExample("search async-await");
        }
예제 #4
0
        public static void SearchingWithConcatingTasks()
        {
            Demo.DisplayHeader("Converting Tasks to observables");

            var results = SearchEngineExample.Search_ConcatingTasks("Rx");

            results
            .RunExample("tasks to observables");
        }