-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathterms.py
More file actions
48 lines (30 loc) · 1.04 KB
/
terms.py
File metadata and controls
48 lines (30 loc) · 1.04 KB
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
45
46
47
48
import asyncio
import time
def sync_function(test_param: str) -> str:
print("This is a synchronous function.")
time.sleep(0.1)
return f"Sync Result: {test_param}"
# ALSO KNOWN AS A COROUTINE FUNCTION
async def async_function(test_param: str) -> str:
print("This is an asynchronous coroutine function.")
await asyncio.sleep(0.1)
return f"Async Result: {test_param}"
async def main():
sync_result = sync_function("Test")
print(sync_result)
# loop = asyncio.get_running_loop()
# future = loop.create_future() # A promise-like object
# print(f"Empty Future: {future}")
# future.set_result("Future Result: Test")
# future_result = await future
# print(future_result)
# coroutine_obj = async_function("Test")
# print(coroutine_obj)
# coroutine_result = await coroutine_obj
# print(coroutine_result)
# task = asyncio.create_task(async_function("Test"))
# print(task)
# task_result = await task
# print(task_result)
if __name__ == "__main__":
asyncio.run(main())