internal static void OnPreShutdown(ShutdownCancellationToken cancel)
 {
     preShutdownSubj.OnNext(cancel);
     if (!cancel.Cancelled)
     {
         preShutdownSubj.OnCompleted();
     }
 }
        public static Unit StopSystem(SystemName system)
        {
            lock (sync)
            {
                if (context == system)
                {
                    context = default(SystemName);
                }

                if (defaultSystem == system)
                {
                    defaultSystem = default(SystemName);
                }

                ActorSystem asystem = null;
                var         token   = new ShutdownCancellationToken(system);
                try
                {
                    Process.OnPreShutdown(token);
                }
                finally
                {
                    if (!token.Cancelled)
                    {
                        try
                        {
                            systems.TryGetValue(system, out asystem);
                            if (asystem != null)
                            {
                                asystem.Dispose();
                            }
                        }
                        finally
                        {
                            systems.TryRemove(system, out asystem);
                            Process.OnShutdown(system);
                        }
                    }
                }
                return(unit);
            }
        }
        public static Unit StopSystem(SystemName system)
        {
            lock (sync)
            {
                if(context == system)
                {
                    context = default(SystemName);
                }

                if(defaultSystem == system)
                {
                    defaultSystem = default(SystemName);
                }

                ActorSystem asystem = null;
                var token = new ShutdownCancellationToken(system);
                try
                {
                    Process.OnPreShutdown(token);
                }
                finally
                {
                    if (!token.Cancelled)
                    {
                        try
                        {
                            systems.TryGetValue(system, out asystem);
                            if (asystem != null)
                            {
                                asystem.Dispose();
                            }
                        }
                        finally
                        {
                            systems.TryRemove(system, out asystem);
                            Process.OnShutdown(system);
                        }
                    }
                }
                return unit;
            }
        }