forked from bedroombuilds/python2rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminimal.py
More file actions
34 lines (27 loc) · 737 Bytes
/
minimal.py
File metadata and controls
34 lines (27 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import asyncio
async def a():
print('Hello ...')
await asyncio.sleep(3)
print("waited")
return 1
async def b():
print('... World!')
return 2
async def main():
await a()
await b()
print("serial\n")
result = await asyncio.gather(a(), b())
print("joined\n")
assert result == [1, 2]
done, pending = await asyncio.wait(
[asyncio.create_task(a()), asyncio.create_task(b())], return_when=asyncio.FIRST_COMPLETED)
for p in pending:
p.cancel()
print("done {}\n".format(done.pop().result()))
futures = [b(), a(), b()]
result = await asyncio.gather(*futures)
print("joined vector\n")
if __name__ == "__main__":
# Python 3.7+
asyncio.run(main())