def connection_delay(self):
        """
        Return the number of milliseconds to wait, based on the connection
        state, before attempting to send data. When connecting or disconnected,
        this respects the reconnect backoff time. When connected, returns a very
        large number to handle slow/stalled connections.
        """
        if self.disconnected() or self.connecting():
            if len(self._gai) > 0:
                return 0
            else:
                time_waited = time.time() - self.last_attempt
                return max(self._reconnect_backoff - time_waited, 0) * 1000
        else:
            # When connecting or connected, we should be able to delay
            # indefinitely since other events (connection or data acked) will
            # cause a wakeup once data can be sent.
            return float('inf')

        Return the number of milliseconds to wait, based on the connection
        state, before attempting to send data. When connecting or disconnected,
        this respects the reconnect backoff time. When connected, returns a very
        large number to handle slow/stalled connections.
        
kafka/conn.py