From 7cc127231df63270a1a87b4c9bb11a3b2eb37abc Mon Sep 17 00:00:00 2001 From: cian Date: Sat, 25 Feb 2023 15:19:36 +0100 Subject: [PATCH] @wip new sleep function --- src/assets/scriptor/__init__.py | 2 ++ src/assets/scriptor/utils.py | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/assets/scriptor/__init__.py b/src/assets/scriptor/__init__.py index c6ecf24..cca291b 100644 --- a/src/assets/scriptor/__init__.py +++ b/src/assets/scriptor/__init__.py @@ -31,6 +31,8 @@ def print(*args, **kwargs): old_print(logging.format_text(*args, **kwargs)) +from .utils import sleep + class prototypes: list = ListModule singleton = SingletonModule diff --git a/src/assets/scriptor/utils.py b/src/assets/scriptor/utils.py index 4491ca7..2c279fb 100644 --- a/src/assets/scriptor/utils.py +++ b/src/assets/scriptor/utils.py @@ -10,3 +10,13 @@ def get_json_object(text: str): except ValueError as e: return False return True + +async def sleep(ms: int): + if is_pyodide_context(): + import manager + await manager.sleep(ms) + else: + import asyncio + if ms > 0 or ms < 0: + ms = float(ms)/1000.0 + await asyncio.sleep(ms)