Invokes a callable, handling both sync and async cases.
(
self, target: Callable[..., Any], args_to_call: dict[str, Any]
)
| 281 | return None |
| 282 | |
| 283 | async def _invoke_callable( |
| 284 | self, target: Callable[..., Any], args_to_call: dict[str, Any] |
| 285 | ) -> Any: |
| 286 | """Invokes a callable, handling both sync and async cases.""" |
| 287 | |
| 288 | # Functions are callable objects, but not all callable objects are functions |
| 289 | # checking coroutine function is not enough. We also need to check whether |
| 290 | # Callable's __call__ function is a coroutine function |
| 291 | is_async = inspect.iscoroutinefunction(target) or ( |
| 292 | hasattr(target, '__call__') |
| 293 | and inspect.iscoroutinefunction(target.__call__) |
| 294 | ) |
| 295 | if is_async: |
| 296 | return await target(**args_to_call) |
| 297 | else: |
| 298 | return target(**args_to_call) |
| 299 | |
| 300 | # TODO: fix call live for function stream. |
| 301 | async def _call_live( |