From 02d298187ece69cac12d70e8c9613316a9615a6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkin=20Y=C4=B1ld=C4=B1r=C4=B1m?= <161759242+berkinyl@users.noreply.github.com> Date: Sat, 2 Nov 2024 23:45:33 +0300 Subject: [PATCH] Create awaitme_berkin_yildirim.py --- Week05/awaitme_berkin_yildirim.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Week05/awaitme_berkin_yildirim.py diff --git a/Week05/awaitme_berkin_yildirim.py b/Week05/awaitme_berkin_yildirim.py new file mode 100644 index 00000000..c1cd83dd --- /dev/null +++ b/Week05/awaitme_berkin_yildirim.py @@ -0,0 +1,17 @@ +import asyncio +from functools import wraps + +def awaitme(func): + """ + Calls the given function and awaits if it's an async function, + otherwise calls it normally. + :param func: The function to be called. + """ + @wraps(func) + async def wrapper(*args, **kwargs): + result = func(*args, **kwargs) + if asyncio.iscoroutine(result): + return await result + return result + + return wrapper