Callable utils
Utilities for calling sync or async functions in PyAgenity.
This module provides helpers to detect async callables and to invoke functions that may be synchronous or asynchronous, handling thread pool execution and awaitables.
Functions:
Name | Description |
---|---|
call_sync_or_async |
Call a function that may be sync or async, returning its result. |
run_coroutine |
Run an async coroutine from a sync context safely. |
Functions¶
call_sync_or_async
async
¶
call_sync_or_async(func, *args, **kwargs)
Call a function that may be sync or async, returning its result.
If the function is synchronous, it runs in a thread pool to avoid blocking the event loop. If the result is awaitable, it is awaited before returning.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Callable[..., Any]
|
The function to call. |
required |
|
Positional arguments for the function. |
()
|
|
|
Keyword arguments for the function. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The result of the function call, awaited if necessary. |
Source code in pyagenity/utils/callable_utils.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
run_coroutine
¶
run_coroutine(func)
Run an async coroutine from a sync context safely.
Source code in pyagenity/utils/callable_utils.py
54 55 56 57 58 59 60 61 62 63 64 65 |
|