Skip to content

Commit 01f9910

Browse files
authored
Update awaitme_furkan_bulut.py
reStructuredText (reST) format docstring added.
1 parent cb9bc72 commit 01f9910

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

Week05/awaitme_furkan_bulut.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,37 @@
11
import asyncio
22

33
def awaitme(f):
4-
async def _awaitme(*args,**kwargs):
5-
func = f(*args,**kwargs)
4+
"""
5+
Decorator to handle synchronous and asynchronous functions.
6+
7+
This decorator allows a function to work seamlessly with both
8+
synchronous and asynchronous code. If the function `f` is a coroutine
9+
(asynchronous), it will await the result. Otherwise, it will treat
10+
it as a regular synchronous function and return the result directly.
11+
12+
:param f: The function to be decorated, which could be either synchronous or asynchronous.
13+
:type f: function
14+
:return: A wrapper function that handles the asynchronous behavior.
15+
:rtype: function
16+
17+
:Example:
18+
19+
#>>> @awaitme
20+
#>>> def sync_func():
21+
#>>> return 42
22+
#>>> sync_func()
23+
42
24+
25+
#>>> @awaitme
26+
#>>> async def async_func():
27+
#>>> return 42
28+
#>>> await async_func()
29+
42
30+
"""
31+
async def _awaitme(*args, **kwargs):
32+
func = f(*args, **kwargs)
633
if asyncio.iscoroutine(func):
734
return await func
835
return func
36+
937
return _awaitme

0 commit comments

Comments
 (0)