Fix async resource functions not being awaited (#1092)
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
This commit is contained in:
parent
3fa7bc7b61
commit
3d67e723e5
1 changed files with 47 additions and 2 deletions
|
|
@ -54,7 +54,12 @@ class FunctionResource(Resource):
|
|||
async def read(self) -> str | bytes:
|
||||
"""Read the resource by calling the wrapped function."""
|
||||
try:
|
||||
result = await self.fn() if inspect.iscoroutinefunction(self.fn) else self.fn()
|
||||
# Call the function first to see if it returns a coroutine
|
||||
result = self.fn()
|
||||
# If it's a coroutine, await it
|
||||
if inspect.iscoroutine(result):
|
||||
result = await result
|
||||
|
||||
if isinstance(result, Resource):
|
||||
return await result.read()
|
||||
elif isinstance(result, bytes):
|
||||
|
|
|
|||
Loading…
Reference in a new issue