namespace Umbraco.Cms.Core.Composing; /// /// /// By default, the component will not execute if Umbraco is restarting. /// public abstract class AsyncComponentBase : IAsyncComponent { /// public async Task InitializeAsync(bool isRestarting, CancellationToken cancellationToken) { if (CanExecute(isRestarting)) { await InitializeAsync(cancellationToken).ConfigureAwait(false); } } /// public async Task TerminateAsync(bool isRestarting, CancellationToken cancellationToken) { if (CanExecute(isRestarting)) { await TerminateAsync(cancellationToken).ConfigureAwait(false); } } /// /// Determines whether the component can execute. /// /// If set to true indicates Umbraco is restarting. /// /// true if the component can execute; otherwise, false. /// protected virtual bool CanExecute(bool isRestarting) => isRestarting is false; /// /// Initializes the component. /// /// The cancellation token. Cancellation indicates that the start process has been aborted. /// /// A representing the asynchronous operation. /// protected abstract Task InitializeAsync(CancellationToken cancellationToken); /// /// Terminates the component. /// /// The cancellation token. Cancellation indicates that the shutdown process should no longer be graceful. /// /// A representing the asynchronous operation. /// protected virtual Task TerminateAsync(CancellationToken cancellationToken) => Task.CompletedTask; }