reflex/reflex/experimental/misc.py
Thomas Brandého 23e979717f
remove all runtime asserts (#4019)
* remove all runtime asserts

* Update reflex/testing.py

Co-authored-by: Masen Furer <m_github@0x26.net>

---------

Co-authored-by: Masen Furer <m_github@0x26.net>
2024-09-27 17:25:22 -07:00

24 lines
685 B
Python

"""Miscellaneous functions for the experimental package."""
import asyncio
from typing import Any
async def run_in_thread(func) -> Any:
"""Run a function in a separate thread.
To not block the UI event queue, run_in_thread must be inside inside a rx.background() decorated method.
Args:
func (callable): 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)