From 2583333045262af3587342626bfca908d53f477b Mon Sep 17 00:00:00 2001 From: sas5188 <148003648+sas5188@users.noreply.github.com> Date: Sun, 17 May 2026 20:20:14 +0300 Subject: [PATCH] Create awaitme_murad_maharramli.py --- Week05/awaitme_murad_maharramli.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Week05/awaitme_murad_maharramli.py diff --git a/Week05/awaitme_murad_maharramli.py b/Week05/awaitme_murad_maharramli.py new file mode 100644 index 00000000..ddc6674b --- /dev/null +++ b/Week05/awaitme_murad_maharramli.py @@ -0,0 +1,19 @@ +import asyncio +from functools import wraps + +def awaitme(func): + """ + A decorator that turns any function into a coroutine. + It passes all arguments to the function and returns its output. + """ + @wraps(func) + async def wrapper(*args, **kwargs): + # Check if the function is already an asynchronous coroutine + if asyncio.iscoroutinefunction(func): + return await func(*args, **kwargs) + + # If it is a synchronous function, run it in a separate thread + # so it behaves as a non-blocking awaitable coroutine + return await asyncio.to_thread(func, *args, **kwargs) + + return wrapper