using System.Collections.Generic;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Threading.Tasks;
using Microsoft.Reactive.Testing;
InitDeviceChangeRequestSubscription();
OnNavigateBackSubscription.Dispose();
Console.WriteLine("OnBack");
private void SimulateDelay(int secs)
Task.Delay(TimeSpan.FromSeconds(secs)).Wait(TimeSpan.FromSeconds(secs));
private void InitDeviceChangeRequestSubscription()
DeviceChangeRequestSubject = new Subject<DeviceStateChangeRequestedRxEvent>();
InitializeDeviceChangeRequestSubscription(DeviceChangeRequestSubject, (rxEvent) => HandleNextThrottledDeviceChangeRequest(rxEvent));
private void InitializeDeviceChangeRequestSubscription(IObservable<DeviceStateChangeRequestedRxEvent> subject, Action<DeviceStateChangeRequestedRxEvent> onNextAction)
var throttledObservable = subject.Throttle(TimeSpan.FromSeconds(3));
DeviceChangeRequestSubscription = throttledObservable.Subscribe(onNextAction);
internal void HandleNextThrottledDeviceChangeRequest(DeviceStateChangeRequestedRxEvent e)
Console.WriteLine(e.State);
Console.WriteLine(_setPoint);
internal IDisposable DeviceChangeRequestSubscription
internal IDisposable OnNavigateBackSubscription
internal Subject<DeviceStateChangeRequestedRxEvent> DeviceChangeRequestSubject;
private int _setPoint = 0;
private void HandleDecrease()
DeviceChangeRequestSubject.OnNext(new DeviceStateChangeRequestedRxEvent("decrease"));
private void HandleIncrease()
if(OnNavigateBackSubscription != null)
OnNavigateBackSubscription.Dispose();
OnNavigateBackSubscription = DeviceChangeRequestSubject.Subscribe();
DeviceChangeRequestSubject.OnNext(new DeviceStateChangeRequestedRxEvent("increase"));
public class DeviceStateChangeRequestedRxEvent
public DeviceStateChangeRequestedRxEvent(string s)