Skip to content

Commit c69fb42

Browse files
authored
Create awaitme_niyazi_cetinkaya.py
1 parent fdb4de0 commit c69fb42

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Week05/awaitme_niyazi_cetinkaya.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import asyncio
2+
3+
def awaitme(func):
4+
async def wrapper(*args, **kwargs):
5+
result = func(*args, **kwargs)
6+
7+
# Check if the result is a coroutine and await it if necessary
8+
if asyncio.iscoroutine(result):
9+
return await result
10+
return result
11+
12+
# This ensures the decorated function can be used both synchronously and asynchronously
13+
if asyncio.iscoroutinefunction(func):
14+
return wrapper
15+
else:
16+
# If it's not a coroutine function, return the original function
17+
return func

0 commit comments

Comments
 (0)