basic flags example with async/await

This commit is contained in:
Luciano Ramalho committed 2015-07-13 23:19:39 -03:00
1 parent a16bd835d2
commit 22cfc8d6dd
2 files changed
+7 -7

No files matched your search

+2
View File
@@ -1,3 +1,5 @@
*.sublime-project
*.sublime-workspace
concurrency/flags/img/*.gif
concurrency/charfinder/charfinder_index.pickle
18-asyncio/charfinder/charfinder_index.pickle
+5 -7
View File
@@ -17,17 +17,15 @@ import aiohttp # <1>
from flags import BASE_URL, save_flag, show, main # <2>
@asyncio.coroutine # <3>
def get_flag(cc):
async def get_flag(cc): # <3>
url = '{}/{cc}/{cc}.gif'.format(BASE_URL, cc=cc.lower())
resp = yield from aiohttp.request('GET', url) # <4>
image = yield from resp.read() # <5>
resp = await aiohttp.request('GET', url) # <4>
image = await resp.read() # <5>
return image
@asyncio.coroutine
def download_one(cc): # <6>
image = yield from get_flag(cc) # <7>
async def download_one(cc): # <6>
image = await get_flag(cc) # <7>
show(cc)
save_flag(image, cc.lower() + '.gif')
return cc