Created
April 6, 2013 01:46
-
-
Save dreid/5324324 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 zope.interface import Interface | |
from twisted.python.components import proxyForInterface | |
class IResolver(Interface): | |
def callback(result): | |
pass | |
def errback(reason): | |
pass | |
class IPromise(Interface): | |
def addCallback(*args, **kwargs): | |
pass | |
def addCallbacks(*args, **kwargs): | |
pass | |
def addBoth(*args, **kwargs): | |
pass | |
def addErrback(*args, **kwargs): | |
pass | |
def cancel(): | |
pass | |
class Promise(proxyForInterface(IPromise)): | |
pass | |
class Resolver(proxyForInterface(IResolver)): | |
pass | |
def splitDeferred(d): | |
return (Promise(d), Resolver(d)) | |
if __name__ == '__main__': | |
from twisted.internet.defer import Deferred | |
import splitd | |
d = Deferred() | |
p, r = splitd.splitDeferred(d) | |
def _print(result): | |
print result | |
p.addCallback(_print) | |
r.callback('foo') | |
d2 = Deferred() | |
p2, r2 = splitDeferred(d2) | |
p2.callback('foo') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment