aboutsummaryrefslogtreecommitdiff
path: root/util.lua
diff options
context:
space:
mode:
Diffstat (limited to 'util.lua')
-rw-r--r--util.lua13
1 files changed, 13 insertions, 0 deletions
diff --git a/util.lua b/util.lua
new file mode 100644
index 0000000..c4067f1
--- /dev/null
+++ b/util.lua
@@ -0,0 +1,13 @@
+function lua_async.yield()
+ local co = assert(coroutine.running(), "yield called outside of an async function")
+
+ setTimeout(lua_async.resume, 0, co)
+
+ coroutine.yield()
+end
+
+function lua_async.sleep(ms)
+ await(Promise(function(resolve)
+ setTimeout(resolve, ms)
+ end))
+end