"""Async utilities.""" import asyncio from functools import partial from typing import Callable from src.backend import logger logger = logger.new_logger(__name__) def run_async(fn: Callable, *args, **kwargs): """Run a synchronous function asynchronously. fn: The function to run. *args: The positional arguments to pass to the function. **kwargs: The keyword arguments to pass to the function. """ loop = asyncio.get_event_loop() fn = partial(fn, *args, **kwargs) return loop.run_in_executor(None, fn)