Skip to content

Utils

Package containing utility modules for Document Processing Orchestrator.

Authors

Hubert Michael Sanyoto (hubert.m.sanyoto@gdplabs.id)

Reviewers

Timotius Nugroho Chandra (timotius.n.chandra@gdplabs.id)

run_async_in_sync(coro)

Run an async coroutine from synchronous code safely.

This function handles the common scenario where you need to call an async function from synchronous code, but you're not sure if there's already an event loop running.

Parameters:

Name Type Description Default
coro Awaitable[T]

The coroutine to run.

required

Returns:

Name Type Description
T T

The result of the coroutine.

Example

async def fetch_data(): ... return "data" result = run_async_in_sync(fetch_data()) print(result) # "data"