none
Selecting items for a TimeSpan from a Hot observable

    Question

  • Whats the easiest way to Select items for a duration from a Hot observable ?

    Here is currently what I came up with. I am sure there are some extensions that I could use

                Stopwatch stopwatch = new Stopwatch();
                IObservable<MyObj> hotObservable= GetObservable();
    
                Subject<MyObj> newObservable= new Subject<MyObj>();
                bool finished = false;
    
    
                bars.Subscribe(a => newObservable.OnNext(a), () =>finished = true);
    
                stopwatch.Start();
                while (!finished && stopwatch.Elapsed < TimeSpan.FromSeconds(10))
                {
                    Thread.Sleep(1);
                }


    Fahad

    Tuesday, June 10, 2014 2:13 PM

Answers

  • This is what I got

    TimeSpan duration = TimeSpan.FromSeconds(5);
    var newObservable = observable
     .TakeUntil(DateTime.Now + duration);
    
    


    Fahad

    • Marked as answer by Fahad349 Tuesday, June 10, 2014 3:20 PM
    Tuesday, June 10, 2014 3:20 PM