Skip to content

Commit

Permalink
upgrade to async syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelliao committed Nov 4, 2015
1 parent ac5faaf commit 9e84c9b
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions samples/async/aio_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@
def index(request):
return web.Response(body=b'<h1>Index</h1>')

def hello(request):
yield from asyncio.sleep(0.5)
async def hello(request):
await asyncio.sleep(0.5)
text = '<h1>hello, %s!</h1>' % request.match_info['name']
return web.Response(body=text.encode('utf-8'))

@asyncio.coroutine
def init(loop):
async def init(loop):
app = web.Application(loop=loop)
app.router.add_route('GET', '/', index)
app.router.add_route('GET', '/hello/{name}', hello)
srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 8000)
srv = await loop.create_server(app.make_handler(), '127.0.0.1', 8000)
print('Server started at http://127.0.0.1:8000...')
return srv

Expand Down

0 comments on commit 9e84c9b

Please sign in to comment.