public static async Task Clear <T>(this AsyncQueue <T> queue) { while (queue.Count > 0) { if (queue.Count > 0) { await queue.TakeAsync(); } } }
public OutputProvider() { Task.Run(async() => { while (true) { LiftEvent @event = await _events.TakeAsync().ConfigureAwait(false); @event.WriteToConsoleLocking(); // is pretty OK since the output is fast } }); }
private async void DoProcessing(CancellationToken token) { try { while (_isStarted) { await _semaphore.WaitAsync(token); var newTask = await _asyncQueue.TakeAsync(token).ConfigureAwait(false); ProcessItem(newTask); } } catch (OperationCanceledException) { } }
protected AsyncAppender() { _task = Task.Run(async() => { while (!IsDisposed) { try { var taken = await _queue.TakeAsync(DisposeToken); if (taken.End) { break; } var tuple = taken.Value; if (tuple.Item1 == null && tuple.Item2 == null) { await FlushAsync(DisposeToken); } else { await AppendAsync(tuple.Item1, tuple.Item2, DisposeToken); if (_flushImmediately) { await FlushAsync(CancellationToken.None); // we flush even cancellation (which is disposal in fact) is in progress } } } catch (OperationCanceledException) { } } catch (Exception e) { Bugs.LastResortEmergencyLog(e); } });