Example #1
0
        public void Never1()
        {
            string result = "";

            var d = AsyncObservable.Never <int>()
                    .Subscribe(i => result += i, ex => result += "E", () => result += "C");

            d.Dispose();
            result
            .Should().Be("");
        }
Example #2
0
        public void Finally2()
        {
            string result = "";

            _ = AsyncObservable.Never <int>()
                .Finally(() => result       += "1")
                .Finally(() => result       += "2")
                .SubscribeAsync(i => result += "N", ex => result += "E", () => result += "C");

            result
            .Should().Be("");
        }
Example #3
0
        public void Never1()
        {
            string result = "";
            var    cts    = new CancellationTokenSource();

            _ = AsyncObservable.Never <int>()
                .SubscribeAsync(i => result += i, ex => result += "E", () => result += "C", cts.Token);

            cts.Cancel();

            result
            .Should().Be("E");
        }
Example #4
0
        public async Task Finally1()
        {
            var    cts    = new CancellationTokenSource();
            string result = "";

            var t = AsyncObservable.Never <int>()
                    .Finally(() => result       += "1")
                    .Finally(() => result       += "2")
                    .SubscribeAsync(i => result += "N", ex => result += "E", () => result += "C", token: cts.Token);

            cts.Cancel();

            await t;

            result
            .Should().Be("12E");
        }
Example #5
0
        public async Task Using2()
        {
            var cts    = new CancellationTokenSource();
            var result = "";
            var t      = AsyncObservable.Using(() => Disposable.Create(() => result += "3"),
                                               _ => AsyncObservable.Using(() => Disposable.Create(() => result += "2"),
                                                                          __ => AsyncObservable.Using(() => Disposable.Create(() => result += "1"),
                                                                                                      ___ => AsyncObservable.Never <Unit>())))
                         .Finally(() => result       += "4")
                         .SubscribeAsync(i => result += "N", ex => result += "E", () => result += "C", ca: cts.Token);

            cts.Cancel();

            await t;

            result
            .Should().Be("1234");
        }