Created
May 13, 2011 06:24
-
-
Save bobpoekert/970080 to your computer and use it in GitHub Desktop.
The @after decorator
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 | |
def noop(*args): | |
return args | |
class proxy(object): | |
def __init__(self, fn): | |
self.defer = Deferred() | |
self.fn = fn | |
def __call__(self, *args, **kwargs): | |
self.defer.callback(fn(*args, **kwargs)) | |
class after(object): | |
def __init__(self, step1, key=noop): | |
self.step1 = step1 | |
self.key = key | |
def __call__(self, step2): | |
def step0(*args, **kwargs): | |
res = proxy(step2) | |
self.step1(*self.key(*args), **kwargs).addCallbacks(res, callbackArgs=args, callbackKeywords=kwargs) | |
return proxy.defer | |
step0.__name__ = "after(%s, %s)" % (self.step1.__name__, step2.__name__) | |
return step0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment