Thomas Brandého пре 1 година
родитељ
комит
e377ce70b6
3 измењених фајлова са 15 додато и 0 уклоњено
  1. 1 0
      .coveragerc
  2. 2 0
      reflex/experimental/__init__.py
  3. 12 0
      reflex/experimental/misc.py

+ 1 - 0
.coveragerc

@@ -6,6 +6,7 @@ omit =
     reflex/__main__.py
     reflex/app_module_for_backend.py
     reflex/components/chakra/*
+    reflex/experimental/*
 
 [report]
 show_missing = true

+ 2 - 0
reflex/experimental/__init__.py

@@ -4,6 +4,7 @@ from types import SimpleNamespace
 
 from ..utils.console import warn
 from . import hooks as hooks
+from .misc import run_in_thread as run_in_thread
 
 warn(
     "`rx._x` contains experimental features and might be removed at any time in the future .",
@@ -11,4 +12,5 @@ warn(
 
 _x = SimpleNamespace(
     hooks=hooks,
+    run_in_thread=run_in_thread,
 )

+ 12 - 0
reflex/experimental/misc.py

@@ -0,0 +1,12 @@
+"""Miscellaneous functions for the experimental package."""
+
+import asyncio
+
+
+async def run_in_thread(func):
+    """Run a function in a separate thread.
+
+    Args:
+        func (callable): The function to run.
+    """
+    await asyncio.get_event_loop().run_in_executor(None, func)