Files
zenml/venv/lib/python3.9/site-packages/graphene/utils/thenables.py
Christian Mantha 2ca0b9ef7c star
2026-03-02 19:10:52 -05:00

26 lines
667 B
Python

"""
This file is used mainly as a bridge for thenable abstractions.
"""
from inspect import isawaitable
def await_and_execute(obj, on_resolve):
async def build_resolve_async():
return on_resolve(await obj)
return build_resolve_async()
def maybe_thenable(obj, on_resolve):
"""
Execute a on_resolve function once the thenable is resolved,
returning the same type of object inputed.
If the object is not thenable, it should return on_resolve(obj)
"""
if isawaitable(obj):
return await_and_execute(obj, on_resolve)
# If it's not awaitable, return the function executed over the object
return on_resolve(obj)