/// <summary> /// Initializes the processor /// </summary> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task InitializeAsync(CancellationToken cancellationToken) { if (Interlocked.Increment(ref _initializationCount) == 1) { var acquiredSemaphore = false; if (cancellationToken.IsCancellationRequested) { throw new TaskCanceledException(); } try { await _lifecycleControl.WaitAsync(cancellationToken).ConfigureAwait(false); acquiredSemaphore = true; await _leaseManager.CreateStoreIfNotExistsAsync(_options, cancellationToken).ConfigureAwait(false); await _checkpointManager.CreateStoreIfNotExistsAsync(_options, cancellationToken).ConfigureAwait(false); } catch (OperationCanceledException e) { throw new TaskCanceledException("Operation Canceled while initializing.", e); } finally { if (acquiredSemaphore) { _lifecycleControl.Release(); } } } }