-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtst0.py
More file actions
34 lines (25 loc) · 962 Bytes
/
tst0.py
File metadata and controls
34 lines (25 loc) · 962 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
#!/usr/bin/python3
import asyncio
import random
async def fun_from_main_thread0():
print("before asynchronous process -> function from")
async def wait_random(max_delay: int = 10) -> float:
'''delay time represent something like asynchronous
operation like promise maker function in js'''
delay = random.uniform(0, max_delay)
''' wait is the a process wait for the previous process
like promise receiver in js '''
await asyncio.sleep(delay)
return delay
async def fun_from_main_thread1():
print("After asynchronous process -> function from")
async def main():
await fun_from_main_thread0()
# Run the coroutine in the background
task = asyncio.create_task(wait_random())
await fun_from_main_thread1() # Execute the function asynchronously
# Wait for and get the result of the coroutine
result = await task
print(result)
if __name__ == "__main__":
asyncio.run(main())