aboutsummaryrefslogtreecommitdiff
path: root/util.lua
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2021-08-06 21:15:57 +0200
committerElias Fleckenstein <eliasfleckenstein@web.de>2021-08-06 21:15:57 +0200
commitbc2179e07b2abf01491a295ed067af9c41b387af (patch)
tree4810250b0c2898813ef2a07ddb8a279455b4868b /util.lua
parent643f41af5ff64405f0860cb4c86aaf733aa28cab (diff)
downloadlua_async-bc2179e07b2abf01491a295ed067af9c41b387af.tar.xz
Revert "More efficient sleep() implementation"
This reverts commit 643f41af5ff64405f0860cb4c86aaf733aa28cab.
Diffstat (limited to 'util.lua')
-rw-r--r--util.lua13
1 files changed, 8 insertions, 5 deletions
diff --git a/util.lua b/util.lua
index b3fc4f7..852b933 100644
--- a/util.lua
+++ b/util.lua
@@ -1,5 +1,9 @@
function lua_async.yield()
- lua_async.sleep(0)
+ local co = assert(coroutine.running(), "yield called outside of an async function")
+
+ setTimeout(lua_async.resume, 0, co)
+
+ coroutine.yield()
end
function lua_async.kill_thread()
@@ -7,10 +11,9 @@ function lua_async.kill_thread()
end
function lua_async.sleep(ms)
- local co = assert(coroutine.running(), "sleep called outside of an async function")
- setTimeout(lua_async.resume, ms, co)
-
- coroutine.yield()
+ await(Promise(function(resolve)
+ setTimeout(resolve, ms)
+ end))
end
function lua_async.run()