Пример #1
0
        protected override async ValueTask ProducerLoopStep(CancellationToken cancellationToken)
        {
            await base.ProducerLoopStep(cancellationToken);

            var timeToNextStep = _auRaStepCalculator.TimeToNextStep;

            if (Logger.IsDebug)
            {
                Logger.Debug($"Waiting {timeToNextStep} for next AuRa step.");
            }
            await TaskExt.DelayAtLeast(timeToNextStep, cancellationToken);
        }
Пример #2
0
        protected override async Task ProducerLoopStep(CancellationToken token)
        {
            // be able to cancel current step block production if needed
            using CancellationTokenSource stepTokenSource = CancellationTokenSource.CreateLinkedTokenSource(token);

            TimeSpan timeToNextStep  = _auRaStepCalculator.TimeToNextStep;
            Task     delayToNextStep = TaskExt.DelayAtLeast(timeToNextStep, token);

            // try produce a block
            Task produceBlockInCurrentStep = base.ProducerLoopStep(stepTokenSource.Token);

            // wait for next step
            if (Logger.IsDebug)
            {
                Logger.Debug($"Waiting {timeToNextStep} for next AuRa step.");
            }
            await delayToNextStep;

            // if block production of now previous step wasn't completed, lets cancel it
            if (!produceBlockInCurrentStep.IsCompleted)
            {
                stepTokenSource.Cancel();
            }
        }