Esempio n. 1
0
        public void TimeDependentExperiment()
        {
            IObservable <double> progressByTime = Observable.Interval(TimeSpan.FromSeconds(.5))
                                                  .Select(v => (double)++v * 10 / 100)
                                                  .Take(10)
                                                  .Publish()
                                                  .Prime();

            IObservable <long> source = Observable.Interval(TimeSpan.FromSeconds(.2))
                                        .TakeUntil(progressByTime.Where(progress => progress == 1));

            IConnectableObservable <Either <long, double> > sourceWithProgress =
                source
                .Pair(progressByTime)
                .Publish();

            IObservable <double> progressOnly = sourceWithProgress.TakeRight().DistinctUntilChanged();
            IObservable <long>   resultOnly   = sourceWithProgress.TakeLeft().TakeLast(1);

            using (progressOnly.Subscribe(ConsoleOutputFormat(Text.Progress, "{0,5:P0}")))
                using (resultOnly.Subscribe(ConsoleOutput(Text.Result)))
                    using (sourceWithProgress.Connect())
                    {
                        WaitForKey();
                    }
        }
Esempio n. 2
0
        public void ValueDependentExperiment()
        {
            IObservable <double> source = Observable.Interval(TimeSpan.FromSeconds(.5))
                                          .Select(v => (double)++v)
                                          .Take(10);

            IConnectableObservable <Either <double, double> > sourceWithProgress =
                source
                .Pair(value => value * 10 / 100)
                .Publish();

            IObservable <double> progressOnly = sourceWithProgress.TakeRight();
            IObservable <double> resultOnly   = sourceWithProgress.TakeLeft().TakeLast(1);

            using (progressOnly.Subscribe(ConsoleOutputFormat(Text.Progress, "{0,5:P0}")))
                using (resultOnly.Subscribe(ConsoleOutput(Text.Result)))
                    using (sourceWithProgress.Connect())
                    {
                        WaitForKey();
                    }
        }