private HandlerBundle CreateBundle(IMessageHandler handler, ISubscription subs = null, IMessage message = null) { Logger.LogInfo("Activating handler, topic = " + (subs.IsNull() ? "Not known" : subs.Topic.Name) + ", channel = " + (subs.IsNull() ? "Not known" : subs.ChannelMonicker)); handler.Initialize(); HandlerBundle bundle = new HandlerBundle { Handler = handler, HostingTask = Task.Run(async() => { IMessageHandler processor = handler as IMessageHandler; // Can be null if being hydrated if (subs.IsNotNull()) { processor.Accept(subs, message); } while (processor.Viable) { if (processor.IsWorking) { await Task.Delay(TaskDelay); } else { await processor.Work(); } } }) }; return(bundle); }