transcribe._sleep: make it usable from deallocate()

If we're closing because of an error, we need to sleep through the old
error, to be able to wait for the "deallocated" message. This might want
to be different: maybe clear the error first, or store the errors in a
list and sleep until a second error happens.
This commit is contained in:
Brian Warner 2016-04-25 16:46:04 -07:00
parent 4eaf88d7d2
commit 8d0bcf9f82

View File

@ -181,13 +181,16 @@ class Wormhole:
return self._signal_error(welcome["error"])
@inlineCallbacks
def _sleep(self):
if self._error: # don't sleep if the bed's already on fire
def _sleep(self, wake_on_error=True):
if wake_on_error and self._error:
# don't sleep if the bed's already on fire, unless we're waiting
# for the fire department to respond, in which case sure, keep on
# sleeping
raise self._error
d = defer.Deferred()
self._sleepers.append(d)
yield d
if self._error:
if wake_on_error and self._error:
raise self._error
def _wakeup(self):