public T poll(long timeout, TimeUnit unit) {
        lock.lock();
        try {
            K key = randomKey();
            long nanos = unit.toNanos(timeout);
            while (key == null && !closed && nanos > 0) {
                try {
                    nanos = condition.awaitNanos(nanos);
                } catch (InterruptedException e) {
                    // Ignore.
                }
                key = randomKey();
            }

            if (key == null) return null;

            Deque<T> queue = queues.get(key);
            T event = queue.poll();

            if (queue.isEmpty()) queues.remove(key);
            inflightKeys.add(key);
            size--;

            return event;
        } finally {
            lock.unlock();
        }
    }
Returns the next {{@link Event}} available. This method blocks for the provided
time and returns null of no event is available.

@param timeout   The timeout.
@param unit      The timeout unit.
@return The next event available or null.
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/runtime/EventAccumulator.java