chore: import upstream snapshot with attribution
Sync docs with Docusaurus / sync (push) Waiting to run
Tests / Check if changed (push) Waiting to run
Tests / format (push) Blocked by required conditions
Tests / check-imports (push) Blocked by required conditions
Tests / Unit / macos-latest (push) Blocked by required conditions
Tests / Unit / ubuntu-latest (push) Blocked by required conditions
Tests / Unit / windows-latest (push) Blocked by required conditions
Tests / mypy (push) Blocked by required conditions
Tests / Integration / ubuntu-latest (push) Blocked by required conditions
Tests / Integration / macos-latest (push) Blocked by required conditions
Tests / Integration / windows-latest (push) Blocked by required conditions
Tests / notify-slack-on-failure (push) Blocked by required conditions
Tests / Mark tests as completed (push) Blocked by required conditions
Docker image release / Build base image (push) Waiting to run
CodeQL / Analyze (python) (push) Has been cancelled
Update Platform Components Table / update (push) Has been cancelled
Sync docs with Docusaurus / sync (push) Waiting to run
Tests / Check if changed (push) Waiting to run
Tests / format (push) Blocked by required conditions
Tests / check-imports (push) Blocked by required conditions
Tests / Unit / macos-latest (push) Blocked by required conditions
Tests / Unit / ubuntu-latest (push) Blocked by required conditions
Tests / Unit / windows-latest (push) Blocked by required conditions
Tests / mypy (push) Blocked by required conditions
Tests / Integration / ubuntu-latest (push) Blocked by required conditions
Tests / Integration / macos-latest (push) Blocked by required conditions
Tests / Integration / windows-latest (push) Blocked by required conditions
Tests / notify-slack-on-failure (push) Blocked by required conditions
Tests / Mark tests as completed (push) Blocked by required conditions
Docker image release / Build base image (push) Waiting to run
CodeQL / Analyze (python) (push) Has been cancelled
Update Platform Components Table / update (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import asyncio
|
||||
from typing import Any
|
||||
|
||||
from haystack import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def _execute_component_async(component_instance: Any, **kwargs: Any) -> dict[str, Any]:
|
||||
"""
|
||||
Run a component asynchronously, preferring its `run_async` method when implemented.
|
||||
|
||||
If the component does not implement `run_async`, its synchronous `run` method is executed in a thread
|
||||
to avoid blocking the event loop.
|
||||
|
||||
:param component_instance: The component to run. Any object exposing a `run` method and optionally a
|
||||
`run_async` coroutine method.
|
||||
:param kwargs: Keyword arguments passed to the component's `run_async` or `run` method.
|
||||
:returns:
|
||||
The component's output dictionary.
|
||||
"""
|
||||
run_async = getattr(component_instance, "run_async", None)
|
||||
if callable(run_async):
|
||||
return await run_async(**kwargs)
|
||||
|
||||
logger.debug(
|
||||
"{component_type} does not implement 'run_async'. Running the synchronous 'run' method in a thread "
|
||||
"to avoid blocking the event loop.",
|
||||
component_type=type(component_instance).__name__,
|
||||
)
|
||||
return await asyncio.to_thread(component_instance.run, **kwargs)
|
||||
Reference in New Issue
Block a user