Created
September 23, 2011 07:51
-
-
Save iley/1236922 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 threading import Thread | |
from time import sleep | |
def yoba_async_call(x, callback): | |
class YobaThread(Thread): | |
def run(self): | |
sleep(1) | |
callback(x * x) | |
YobaThread().start() | |
class YobaMagic(object): | |
def yoba_decorator(f): | |
def res(self, *args, **nargs): | |
g = None | |
def yoba_callback(result): | |
print "yoba callback" | |
g.send(result) | |
next(g) | |
g = f(self, yoba_callback, *args, **nargs) | |
next(g) | |
return res | |
@yoba_decorator | |
def response(self, magic_callback): | |
print "start reponse" | |
yoba_async_call(12, magic_callback) | |
result = yield | |
yield | |
print "response is %d" % result | |
yoba_async_call(13, magic_callback) | |
result = yield | |
yield | |
print "response is %d" % result | |
yield | |
x = YobaMagic() | |
x.response() | |
print "ololoski ololo" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment