static IDisposable NotifyCluster(Option <ICluster> cluster, long timestamp) => cluster.Map(c => { c.PublishToChannel(ClusterOnlineKey, new ClusterOnline { Name = c.NodeName.Value, Timestamp = timestamp }); return(c.SubscribeToChannel <ClusterOnline>(ClusterOnlineKey) .Where(node => node.Name == c.NodeName.Value && node.Timestamp > timestamp) .Take(1) .Subscribe(_ => { var cancel = new CancelShutdown(); try { Process.OnPreShutdown(cancel); } finally { if (!cancel.Cancelled) { Process.shutdownAll(); c.Disconnect(); } } })); }) .IfNone(() => Observable.Return(new ClusterOnline()).Take(1).Subscribe());
internal static void OnPreShutdown(CancelShutdown cancel) { preShutdownSubj.OnNext(cancel); if (!cancel.Cancelled) { preShutdownSubj.OnCompleted(); } }