timer examples
This commit is contained in:
19
concurrency/timer.py
Normal file
19
concurrency/timer.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import asyncio
|
||||
|
||||
@asyncio.coroutine
|
||||
def show_remaining():
|
||||
remaining = 5
|
||||
while remaining:
|
||||
print('Remaining: ', remaining)
|
||||
yield from asyncio.sleep(1)
|
||||
remaining -= 1
|
||||
|
||||
def main():
|
||||
loop = asyncio.get_event_loop()
|
||||
try:
|
||||
loop.run_until_complete(show_remaining())
|
||||
finally:
|
||||
loop.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user