def when_finished(self): """ Get a deferred that will be fired when the connection is closed. """ d = Deferred() self._waiting.append(d) return d