
* add more type annotations through the code * add typing in reflex/utils * misc typing * more typings * state typing * keep typing * typing init and utils * more typing for components * fix attempt for 3.9 * need more __future * more typings * type event plz * type model * type vars/base.py * enable 'ANN001' for reflex folder (ignore tests and benchmarks) * fix pyi * add missing annotations * use more precise error when ignoring
24 lines
704 B
Python
24 lines
704 B
Python
"""Miscellaneous functions for the experimental package."""
|
|
|
|
import asyncio
|
|
from typing import Any, Callable
|
|
|
|
|
|
async def run_in_thread(func: Callable) -> Any:
|
|
"""Run a function in a separate thread.
|
|
|
|
To not block the UI event queue, run_in_thread must be inside inside a rx.event(background=True) decorated method.
|
|
|
|
Args:
|
|
func: The non-async function to run.
|
|
|
|
Raises:
|
|
ValueError: If the function is an async function.
|
|
|
|
Returns:
|
|
Any: The return value of the function.
|
|
"""
|
|
if asyncio.coroutines.iscoroutinefunction(func):
|
|
raise ValueError("func must be a non-async function")
|
|
return await asyncio.get_event_loop().run_in_executor(None, func)
|