using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Timing
{
    class Example48
    {
        public static void MeasureInterval()
        {
            // Listing 11-48
            // Zmodyfikowany by można było zrezygnować z subskrypcji
            IObservable<long> ticks = Observable.Interval(TimeSpan.FromSeconds(0.75));
            IObservable<TimeInterval<long>> timed = ticks.TimeInterval();
            IDisposable sub = timed.Subscribe(x => Console.WriteLine("Zdarzenie {0} trwało {1:F3}",
                                                   x.Value, x.Interval.TotalSeconds));

            Thread.Sleep(4700);
            sub.Dispose();
        }
    }
}
