private static async Task ListenLoopExecuted( Queue <Func <Task> > actions, IMessageProcessingStrategy messageProcessingStrategy) { var initalActionCount = (double)actions.Count; var timeout = MinTaskDuration + TimeSpan.FromMilliseconds(initalActionCount / 100); var stopwatch = Stopwatch.StartNew(); while (actions.Any()) { var batch = GetFromFakeSnsQueue(actions, messageProcessingStrategy.MaxConcurrency); if (batch.Count < 1) { break; } foreach (var action in batch) { (await messageProcessingStrategy.StartWorkerAsync(action, CancellationToken.None)).ShouldBeTrue(); } messageProcessingStrategy.MaxConcurrency.ShouldBeGreaterThanOrEqualTo(0); (await messageProcessingStrategy.WaitForAvailableWorkerAsync()).ShouldBeGreaterThan(0); messageProcessingStrategy.MaxConcurrency.ShouldBeGreaterThan(0); } }
private Task <bool> TryHandleMessageAsync(Amazon.SQS.Model.Message message, CancellationToken ct) { async Task DispatchAsync() { await _messageDispatcher.DispatchMessage(message, ct).ConfigureAwait(false); } return(_messageProcessingStrategy.StartWorkerAsync(DispatchAsync, ct)); }