示例#1
0
        public void Add(T value)
        {
            _values.Enqueue(value);

            while (_values.Count >= BatchSize && ThreadSafety.TryLock(_values, () =>
            {
                // Use 'if' instead of 'while' to ensure a single 'Add' operation doesn't get trapped in the job of batching.
                if (_values.Count >= BatchSize)
                {
                    _batches.Enqueue(_values.AsDequeueingEnumerable().Take(BatchSize).ToArray());
                }
            }))
            {
            }
        }