From 35bb47ac6cadd961469a0d3eae44fee670d7c6ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20Balc=C4=B1?= <148548201+MehmetxBalci@users.noreply.github.com> Date: Sat, 4 Apr 2026 20:39:15 +0300 Subject: [PATCH] Add awaitme decorator for async function handling Implement an awaitable decorator to handle async functions. --- Week05/awaitme_mehmet_balci.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Week05/awaitme_mehmet_balci.py diff --git a/Week05/awaitme_mehmet_balci.py b/Week05/awaitme_mehmet_balci.py new file mode 100644 index 00000000..c8bb64d0 --- /dev/null +++ b/Week05/awaitme_mehmet_balci.py @@ -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