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 10
10
import sys
11
11
12
12
13
- @asyncio .coroutine # <1>
14
- def spin (msg ): # <2>
13
+ async def spin (msg ): # <1>
15
14
write , flush = sys .stdout .write , sys .stdout .flush
16
15
for char in itertools .cycle ('|/-\\ ' ):
17
16
status = char + ' ' + msg
18
17
write (status )
19
18
flush ()
20
19
write ('\x08 ' * len (status ))
21
20
try :
22
- yield from asyncio .sleep (.1 ) # <3>
21
+ await asyncio .sleep (.1 ) # <3>
23
22
except asyncio .CancelledError : # <4>
24
23
break
25
24
write (' ' * len (status ) + '\x08 ' * len (status ))
26
25
27
26
28
- @asyncio .coroutine
29
- def slow_function (): # <5>
27
+ async def slow_function (): # <5>
30
28
# pretend waiting a long time for I/O
31
- yield from asyncio .sleep (3 ) # <6>
29
+ await asyncio .sleep (3 ) # <6>
32
30
return 42
33
31
34
32
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>
38
35
print ('spinner object:' , spinner ) # <9>
39
- result = yield from slow_function () # <10>
36
+ result = await slow_function () # <10>
40
37
spinner .cancel () # <11>
41
38
return result
42
39
You can’t perform that action at this time.
0 commit comments