-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathex03.py
44 lines (37 loc) · 931 Bytes
/
ex03.py
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
35
36
37
38
39
40
41
42
43
44
import asyncio
from time import time
fake_users = [
{
"id": 1,
"name": "April Murphy",
"company": "Bailey Inc",
"email": "[email protected]",
},
{
"id": 2,
"name": "Emily Alexander",
"company": "Martinez-Smith",
"email": "[email protected]",
},
{
"id": 3,
"name": "Patrick Jones",
"company": "Young, Pruitt and Miller",
"email": "[email protected]",
},
]
async def get_user_async(uid: int) -> dict:
await asyncio.sleep(0.5)
(user,) = list(filter(lambda user: user["id"] == uid, fake_users))
return user
async def main():
r = []
for i in range(1, 4):
r.append(get_user_async(i))
return await asyncio.gather(*r)
if __name__ == "__main__":
start = time()
result = asyncio.run(main())
for r in result:
print(r)
print(time() - start)