Skip to content

Instantly share code, notes, and snippets.

@iley
Created September 23, 2011 07:51
Show Gist options
  • Save iley/1236922 to your computer and use it in GitHub Desktop.
Save iley/1236922 to your computer and use it in GitHub Desktop.
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