reactor-core/src/main/java/reactor/core/publisher/Operators.java
public static <T> void onDiscardQueueWithClear(
			@Nullable Queue<T> queue,
			Context context,
			@Nullable Function<T, Stream<?>> extract) {
		if (queue == null) {
			return;
		}

		Consumer<Object> hook = context.getOrDefault(Hooks.KEY_ON_DISCARD, null);
		if (hook == null) {
			queue.clear();
			return;
		}

		try {
			for(;;) {
				T toDiscard = queue.poll();
				if (toDiscard == null) {
					break;
				}

				if (extract != null) {
					extract.apply(toDiscard)
					       .forEach(hook);
				}
				else {
					hook.accept(toDiscard);
				}
			}
		}
		catch (Throwable t) {
			log.warn("Error in discard hook while discarding and clearing a queue", t);
		}
	}
public static <T> void onDiscardQueueWithClear(
			@Nullable Queue<T> queue,
			Context context,
			@Nullable Function<T, Stream<?>> extract) {
		if (queue == null) {
			return;
		}

		Consumer<Object> hook = context.getOrDefault(Hooks.KEY_ON_DISCARD, null);
		if (hook == null) {
			queue.clear();
			return;
		}

		try {
			for(;;) {
				T toDiscard = queue.poll();
				if (toDiscard == null) {
					break;
				}

				if (extract != null) {
					extract.apply(toDiscard)
					       .forEach(hook);
				}
				else {
					hook.accept(toDiscard);
				}
			}
		}
		catch (Throwable t) {
			log.warn("Error in discard hook while discarding and clearing a queue", t);
		}
	}
Invoke a (local or global) hook that processes elements that get discarded
en masse after having been enqueued, due to cancellation or error. This method
also empties the {@link Queue} (either by repeated {@link Queue#poll()} calls if
a hook is defined, or by {@link Queue#clear()} as a shortcut if no hook is defined).

@param queue the queue that is being discarded and cleared
@param context the context in which to look for a local hook
@param extract an optional extractor method for cases where the queue doesn't
directly contain the elements to discard
@param <T> the type of the element
@see #onDiscardMultiple(Stream, Context)
@see #onDiscardMultiple(Collection, Context)
@see #onDiscard(Object, Context)