diff --git a/Week05/awaitme_miray_cengil.py b/Week05/awaitme_miray_cengil.py new file mode 100644 index 00000000..675dc5f6 --- /dev/null +++ b/Week05/awaitme_miray_cengil.py @@ -0,0 +1,16 @@ +import asyncio + +def awaitme(func): + """ + A decorator that turns any function into a coroutine. + It properly passes all arguments to the function. + If the function returns a value, the decorator will return it. + """ + async def wrapper(*args, **kwargs): + if asyncio.iscoroutinefunction(func): + return await func(*args, **kwargs) + else: + loop = asyncio.get_event_loop() + return await loop.run_in_executor(None, lambda: func(*args, **kwargs)) + + return wrapper