sync#
- starlite.utils.sync.is_async_callable(value: Callable[[P], T]) TypeGuard[Callable[[P], Awaitable[T]]]#
Extend
asyncio.iscoroutinefunction()to additionally detect asyncfunctools.partial()objects and class instances withasync def __call__()defined.- Parameters:
value – Any
- Returns:
Bool determining if type of
valueis an awaitable.
- class starlite.utils.sync.AsyncCallable#
Bases:
Generic[P,T]Wrap a callable into an asynchronous callable.
- __init__(fn: Callable[[P], T]) None#
Initialize the wrapper from any callable.
- Parameters:
fn – Callable to wrap - can be any sync or async callable.
- async __call__(*args: ~typing.~P, **kwargs: ~typing.~P) T#
Proxy the wrapped function’s call method.
- Parameters:
*args – Args of the wrapped function.
**kwargs – Kwargs of the wrapper function.
- Returns:
The return value of the wrapped function.
- starlite.utils.sync.as_async_callable_list(value: Union[Callable, List[Callable]]) List[AsyncCallable]#
Wrap callables in
AsyncCallables.- Parameters:
value – A callable or list of callables.
- Returns:
A list of AsyncCallable instances
- starlite.utils.sync.async_partial(fn: Callable) Callable#
Wrap a given sync function making it async.
In difference to the
asyncio.run_sync()function, it allows for passing kwargs.- Parameters:
fn – A sync callable to wrap.
- Returns:
A wrapper