Created
October 20, 2015 08:16
-
-
Save meejah/d27e9059e9cb54f1d00a to your computer and use it in GitHub Desktop.
twisted: mixed @inlineCallbacks + Deferred
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from twisted.internet.defer import Deferred, inlineCallbacks, returnValue | |
d0 = Deferred() | |
d1 = Deferred() | |
d2 = Deferred() | |
@inlineCallbacks | |
def foo(arg): | |
print 'foo', arg | |
x = yield d1 | |
x = 'foo-' + str(x) | |
print 'foo() is returning', x | |
returnValue(x) | |
def quux(arg): | |
print "quux", arg | |
d = foo('blam') | |
print 'quux() is returning', d | |
return d | |
@inlineCallbacks | |
def bar(arg): | |
print 'bar', arg | |
z = yield quux(arg) | |
print 'bar() is returning', z | |
returnValue(z) | |
d2.callback('d2') | |
d1.callback('d1') | |
d0.addCallback(bar) | |
assert d2.result == 'd2' | |
assert d1.result == 'd1' | |
d0.callback('d0') | |
assert d2.result == 'd2' | |
assert d0.result == 'foo-d1' | |
# somehow, d1's result has become None here ... | |
assert d1.result == 'd1' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment