Skip to content

Commit 9e84c9b

Browse files
committed
upgrade to async syntax
1 parent ac5faaf commit 9e84c9b

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

samples/async/aio_web.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,16 @@
1414
def index(request):
1515
return web.Response(body=b'<h1>Index</h1>')
1616

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

22-
@asyncio.coroutine
23-
def init(loop):
22+
async def init(loop):
2423
app = web.Application(loop=loop)
2524
app.router.add_route('GET', '/', index)
2625
app.router.add_route('GET', '/hello/{name}', hello)
27-
srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 8000)
26+
srv = await loop.create_server(app.make_handler(), '127.0.0.1', 8000)
2827
print('Server started at http://127.0.0.1:8000...')
2928
return srv
3029

0 commit comments

Comments
 (0)