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
19 changes: 19 additions & 0 deletions Week05/awaitme_murad_maharramli.py
Original file line number Diff line number Diff line change
@@ -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
Loading