public bool TryFilterNewPayload(T payload) { if (PayloadQueue.Contains(payload)) { return(false); } else if (PayloadQueue.Count < MaxQueueItems) { PayloadQueue.Enqueue(payload); return(true); } else { PayloadQueue.TryDequeue(out _); PayloadQueue.Enqueue(payload); return(true); } }
public async Task <bool> TryFilterNewPayload(T payload, Func <T, string> keyExpression) { var payloadKey = $"{typeof(T).Name}:{keyExpression(payload)}"; using (await _payloadLock.WaitAsync(payloadKey)) { if (PayloadQueue.Contains(payload)) { return(false); } else if (PayloadQueue.Count < MaxQueueItems) { PayloadQueue.Enqueue(payload); return(true); } else { PayloadQueue.TryDequeue(out _); PayloadQueue.Enqueue(payload); return(true); } } }