private async ValueTask Consume(ICollection <ProcItem <T> > items) { try { if (items.IsNullOrEmpty()) { return; } var list = items.Select(m => m.Item).ToArray(); await OnConsume.InvokeAsync(this, list).DonotCapture(); return; } catch (Exception ex) { var list = items.CastTo <IReadOnlyList <ProcItem <T> > >(); OnException.Invoke(this, ProcItem.CreateEx(list, ex, -1)); } var(retry, discard) = items.Partition(m => m.ErrorTimes < _maxRetryTimes); retry.ForEach(m => { m.ErrorTimes++; _items.TryAdd(m); }); var toDiscard = discard.Select(m => m.Item).ToArray(); if (toDiscard.Any()) { OnDiscard.Invoke(this, toDiscard); } }
public static void InvokeOnConsume(OnConsumeEventArgs e) { OnConsume?.Invoke(e); }