/// <summary> /// Stop our server /// </summary> public IObservable <NyxNodeStatus> Stop() { if (_serverTask == null || Status == NyxNodeStatus.Stopped) { return(NodeStatus.StoppedObservable()); } var result = Observable.Create <NyxNodeStatus>(o => { var dispose = NodeStatusStream.Subscribe(n => { if (n != NyxNodeStatus.Stopped) { return; } o.OnNext(n); o.OnCompleted(); }); return(new CompositeDisposable(dispose)); }); _serverCancelationSource.Cancel(); _serverEvent.Set(); return(result); }
/// <summary> /// Starts our server /// </summary> public IObservable <NyxNodeStatus> Start() { if (_serverTask != null || _serverTask?.Status == TaskStatus.Running || Status == NyxNodeStatus.Started) { return(NodeStatus.StartedObservable()); } var result = Observable.Create <NyxNodeStatus>(o => { var dispose = NodeStatusStream.Subscribe(n => { if (n != NyxNodeStatus.Started) { return; } o.OnNext(n); o.OnCompleted(); }); return(new CompositeDisposable(dispose)); }); _serverTask = Task.Factory.StartNew(ServerLoop, _serverCancelToken, TaskCreationOptions.LongRunning, TaskScheduler.Default); IsStarted = true; return(result); }