Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Week05/awaitme_miray_cengil.py
Original file line number Diff line number Diff line change
@@ -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
Loading