File tree Expand file tree Collapse file tree 1 file changed +7
-10
lines changed
Expand file tree Collapse file tree 1 file changed +7
-10
lines changed Original file line number Diff line number Diff line change 1010import sys
1111
1212
13- @asyncio .coroutine # <1>
14- def spin (msg ): # <2>
13+ async def spin (msg ): # <1>
1514 write , flush = sys .stdout .write , sys .stdout .flush
1615 for char in itertools .cycle ('|/-\\ ' ):
1716 status = char + ' ' + msg
1817 write (status )
1918 flush ()
2019 write ('\x08 ' * len (status ))
2120 try :
22- yield from asyncio .sleep (.1 ) # <3>
21+ await asyncio .sleep (.1 ) # <3>
2322 except asyncio .CancelledError : # <4>
2423 break
2524 write (' ' * len (status ) + '\x08 ' * len (status ))
2625
2726
28- @asyncio .coroutine
29- def slow_function (): # <5>
27+ async def slow_function (): # <5>
3028 # pretend waiting a long time for I/O
31- yield from asyncio .sleep (3 ) # <6>
29+ await asyncio .sleep (3 ) # <6>
3230 return 42
3331
3432
35- @asyncio .coroutine
36- def supervisor (): # <7>
37- spinner = asyncio .async (spin ('thinking!' )) # <8>
33+ async def supervisor (): # <7>
34+ spinner = asyncio .ensure_future (spin ('thinking!' )) # <8>
3835 print ('spinner object:' , spinner ) # <9>
39- result = yield from slow_function () # <10>
36+ result = await slow_function () # <10>
4037 spinner .cancel () # <11>
4138 return result
4239
You can’t perform that action at this time.
0 commit comments