close method
Closes the publisher after draining the queue: every entry accepted
before closing is processed, including entries published while a batch
was in flight. Entries returned to the retry buffer after closing are
dropped and handed to onDropped.
A retry that was waiting out retryDelay is not waited for: the pending timer is cancelled and one prompt final attempt is made instead, so shutdown latency does not scale with retryDelay.
After closing, publishing throws a StateError and flush hands back this same future. Repeated calls return it too.
Do not await this (or flush) from inside handle: closing waits for the running batch to complete, so it would deadlock. Calling it without awaiting is fine and is the way to shut a publisher down from its own handler — a sink that discovers it is dead can start the close and return; the close then waits for that same batch to finish, as it does for any other.
Implementation
@override
Future<void> close() {
_closed = true;
return _closeFuture ??= _close();
}