Skip to content

Instantly share code, notes, and snippets.

@jml
Last active February 10, 2016 16:51
Show Gist options
  • Save jml/7c0d36b66ff92f0044f8 to your computer and use it in GitHub Desktop.
Save jml/7c0d36b66ff92f0044f8 to your computer and use it in GitHub Desktop.
Deferred equivalent of sleep?
def waitFor(clock, delay, deferred):
"""
Usage::
waitFor(reactor, 20, d).addCallback(print)
Will wait for 20s before calling ``print`` with the result of ``d``.
"""
# H/T @tomprince
return deferred.addCallback(lambda x: deferLater(clock, delay, lambda: x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment