Skip to content

Instantly share code, notes, and snippets.

@dreid
Created April 6, 2013 01:46
Show Gist options
  • Save dreid/5324324 to your computer and use it in GitHub Desktop.
Save dreid/5324324 to your computer and use it in GitHub Desktop.
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