Skip to content
Browse files

Merge branch 'sugar' of https://github.com/kmike/brukva into kmike-sugar

  • Loading branch information...
2 parents 0b39a6e + 6a695a4 commit 39bf7dad964ab672a99112d83b613265495a4358 @evilkost committed Apr 13, 2011
Showing with 14 additions and 9 deletions.
  1. +10 −0 brukva/client.py
  2. +4 −9 demos/simple/app.py
View
10 brukva/client.py
@@ -220,11 +220,21 @@ def get_value(value):
def reply_ttl(r, *args, **kwargs):
return r != -1 and r or None
+
+class _AsyncWrapper(object):
+ def __init__(self, obj):
+ self.obj = obj
+
+ def __getattr__(self, item):
+ return async(getattr(self.obj, item), cbname='callbacks')
+
+
class Client(object):
def __init__(self, host='localhost', port=6379, password=None, reconnect=False, io_loop=None):
self._io_loop = io_loop or IOLoop.instance()
self.connection = Connection(host, port, self.on_reconnect, io_loop=self._io_loop)
+ self.async = _AsyncWrapper(self)
self.queue = []
self.current_cmd_line = None
self.subscribed = False
View
13 demos/simple/app.py
@@ -5,7 +5,6 @@
import tornado.ioloop
from brukva import adisp
import logging
-from functools import partial
logging.basicConfig(level=logging.DEBUG)
@@ -18,11 +17,7 @@
def on_set(result):
- (error, data) = result
- log.debug("set result: %s" % (error or data,))
-
-
-async = partial(adisp.async, cbname='callbacks')
+ log.debug("set result: %s" % result)
c.set('foo', 'Lorem ipsum #1', on_set)
@@ -34,9 +29,9 @@ class MainHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
@adisp.process
def get(self):
- (_, foo) = yield async(c.get)('foo')
- (_, bar) = yield async(c.get)('bar')
- (_, zar) = yield async(c.get)('zar')
+ foo = yield c.async.get('foo')
+ bar = yield c.async.get('bar')
+ zar = yield c.async.get('zar')
self.set_header('Content-Type', 'text/html')
self.render("template.html", title="Simple demo", foo=foo, bar=bar, zar=zar)

0 comments on commit 39bf7da

Please sign in to comment.
Something went wrong with that request. Please try again.