Example #1
0
 public void LinkLifetime(IStartupShutdownSlim nestedComponent)
 {
     Contract.Requires(!StartupStarted, "Nested components must be linked before startup");
     if (nestedComponent != null)
     {
         _nestedComponents.Add(nestedComponent);
     }
 }
            public TestServerProvider(IStartupShutdownSlim server, Func <TStore> getStore)
            {
                Assert.NotNull(server);
                Assert.NotNull(getStore);

                Server    = server;
                _getStore = getStore;
            }
Example #3
0
        private static async Task <BoolResult> ShutdownWithTimeoutAsync(Context context, IStartupShutdownSlim server, TimeSpan timeout)
        {
            var shutdownTask = server.ShutdownAsync(context);

            if (await Task.WhenAny(shutdownTask, Task.Delay(timeout)) != shutdownTask)
            {
                return(new BoolResult($"Server shutdown didn't finished after '{timeout}'."));
            }

            // shutdownTask is done already. Just getting the result out of it.
            return(await shutdownTask);
        }
 public TestServerProvider(IStartupShutdownSlim server, TStore store)
     : this(server ?? store, () => store)
 {
 }
 public ShutdownGuard(IStartupShutdownSlim component, Context context)
 {
     _component = component;
     _context   = context;
 }
        /// <summary>
        /// Creates a lexically scoped guard to shutdown a component
        /// </summary>
        public static async Task <IAsyncDisposable> StartupWithAutoShutdownAsync(this IStartupShutdownSlim component, Context context)
        {
            await component.StartupAsync(context).ThrowIfFailureAsync();

            return(new ShutdownGuard(component, context));
        }