static Task CallOnStart(OrderedObserver observer, CancellationToken cancellationToken)
 {
     try
     {
         return(observer.Observer?.OnStart(cancellationToken) ?? Task.CompletedTask);
     }
     catch (Exception ex)
     {
         return(Task.FromException(ex));
     }
 }
Beispiel #2
0
        public IDisposable Subscribe(int stage, ILifecycleObserver observer)
        {
            if (observer == null)
            {
                throw new ArgumentNullException(nameof(observer));
            }

            var orderedObserver = new OrderedObserver(stage, observer);

            this.subscribers.TryAdd(orderedObserver, orderedObserver);
            return(new Disposable(() => Remove(orderedObserver)));
        }
        public virtual IDisposable Subscribe(string observerName, int stage, ILifecycleObserver observer)
        {
            if (observer == null)
            {
                throw new ArgumentNullException(nameof(observer));
            }
            if (this.highStage.HasValue)
            {
                throw new InvalidOperationException("Lifecycle has already been started.");
            }

            var orderedObserver = new OrderedObserver(stage, observer);

            this.subscribers.Add(orderedObserver);
            return(new Disposable(() => this.subscribers.Remove(orderedObserver)));
        }