@Override
        public void run() {
            logger.info("Checking for pending messages to complete before close on {}", this);

            if (isOkToClose() || System.currentTimeMillis() > checkUntil) {
                shutdown(future);
                boolean interrupted = false;
                try {
                    while (null == self) {
                        try {
                            Thread.sleep(1);
                        } catch (InterruptedException e) {
                            interrupted = true;
                        }
                    }
                    self.cancel(false);
                } finally {
                    if (interrupted) {
                        Thread.currentThread().interrupt();
                    }
                }
            }
        }
Self-cancelling tasks that periodically checks for the pending queue to clear before shutting down the
{@code Connection}. Once it does that, it self cancels the scheduled job in the executor.
gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Connection.java