Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Week05/awaitme_mehmet_balci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from functools import wraps
from inspect import isawaitable


def awaitme(func):
# Preserve original function metadata (name, docstring, etc.)
@wraps(func)
async def inner(*args, **kwargs):
# Call the original function with given arguments
value = func(*args, **kwargs)

# Check if the returned value can be awaited (e.g., coroutine, future)
if isawaitable(value):
# Await the result if it is awaitable
return await value

# Otherwise, return the result directly
return value

# Return the async wrapper function
return inner
Loading