コード例 #1
0
        public void Race_While()
        {
            for (int i = 0; i < TestHelper.RACE_LOOPS; i++)
            {
                var us = new UnicastSubject <int>();

                var to = new TestObserver <int>();

                TestHelper.Race(() =>
                {
                    for (int j = 0; j < 1000; j++)
                    {
                        us.OnNext(j);
                    }
                    us.OnCompleted();
                },
                                () =>
                {
                    us.BlockingSubscribeWhile(v =>
                    {
                        to.OnNext(v);
                        return(true);
                    }, to.OnError, to.OnCompleted);
                });

                to.AssertValueCount(1000)
                .AssertNoError()
                .AssertCompleted();
            }
        }
コード例 #2
0
        public void Basic_While_Dispose()
        {
            var to  = new TestObserver <int>();
            var sad = new SingleAssignmentDisposable();
            var cdl = new CountdownEvent(2);
            var us  = new UnicastSubject <int>();

            Task.Factory.StartNew(() =>
            {
                while (to.ItemCount != 5)
                {
                    ;
                }
                sad.Dispose();
                cdl.Signal();
            });

            Task.Factory.StartNew(() =>
            {
                us.Emit(1, 2, 3, 4, 5);
                cdl.Signal();
            });

            us.BlockingSubscribeWhile(v => {
                to.OnNext(v);
                return(true);
            }, to.OnError, to.OnCompleted, d => sad.Disposable = d);

            to.AssertValuesOnly(1, 2, 3, 4, 5);

            Assert.True(cdl.Wait(3000));

            Assert.False(us.HasObserver());
        }