Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

bit more documentation

  • Loading branch information...
commit a62abc7e1300785a4f16ec24f9c4e31ff23a5fec 1 parent 09948be
Jeremy Kelley authored
Showing with 52 additions and 1 deletion.
  1. +52 −1 README.md
View
53 README.md
@@ -23,5 +23,56 @@ via [Nose](http://code.google.com/p/python-nose/).
## Usage
-See the comments in (routes.py) or (async_yield.py).
+The best source of information is the comments in routes.py or async_yield.py.
+They're fairly well commented and give a better understanding of the libs.
+
+### routes
+
+Here's a simple example.
+
+ import tornado.web
+ from tornado_addons.route import route
+
+ @route('/blah')
+ class SomeHandler(tornado.web.RequestHandler):
+ pass
+
+ t = tornado.web.Application(route.get_routes(), {'some app': 'settings'}
+
+
+### Async yields
+
+Here's an example with normal callbacks.
+
+ from tornado.httpclient import AsyncHTTPClient
+
+ @tornado.web.asynchronous
+ class SomeHandler(tornado.web.RequestHandler):
+ def get(self):
+ self.somedata = 'xxx'
+ AsyncHTTPClient.fetch(
+ 'http://over/there',
+ callback=self.my_async_http_cb )
+
+ def my_async_http_cb(self, fetch_data):
+ # do stuff here....
+ self.write(self.somedata)
+
+
+Or, you can wrap your methods with async_yield...
+
+ from tornado_addons.async_yield import async_yield, AsyncYieldMixin
+
+ class SomeHandler(tornado.web.RequestHandler, AsyncYieldMixin):
+ @async_yield
+ def get(self):
+ somedata = 'xxx'
+ fetchdata = yield AsyncHTTPClient.fetch(
+ 'http://over/there',
+ callback=self.async_cb )
+ self.write(somedata)
+
+The @async_yield wrapper doesn't work for every method with callbacks but it
+does cleanup your RequestHandlers quite nicely and really streamlines workflow.
+
Please sign in to comment.
Something went wrong with that request. Please try again.