From ba7ca5ee48e531182ec2cff683081a2f1f4fb31f Mon Sep 17 00:00:00 2001 From: Katex <67821908+katex35@users.noreply.github.com> Date: Fri, 1 Nov 2024 15:33:37 +0300 Subject: [PATCH] Create awaitme_gokay_sahin.py --- Week05/awaitme_gokay_sahin.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Week05/awaitme_gokay_sahin.py diff --git a/Week05/awaitme_gokay_sahin.py b/Week05/awaitme_gokay_sahin.py new file mode 100644 index 00000000..4c6babc2 --- /dev/null +++ b/Week05/awaitme_gokay_sahin.py @@ -0,0 +1,19 @@ +import asyncio + + +def awaitme(func): + """ + Converts a function into a coroutine. + + :return: Coroutine version of the function. + :rtype: Coroutine + """ + async def wrapper(*args, **kwargs): + result = func(*args, **kwargs) + + if asyncio.iscoroutine(result): + return await result + else: + return result + + return wrapper