aboutsummaryrefslogtreecommitdiff
path: root/util.lua
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2021-08-06 21:19:35 +0200
committerElias Fleckenstein <eliasfleckenstein@web.de>2021-08-06 21:19:35 +0200
commit5c5c5d17f469a686375aeff95b3ccb9c2ee9767b (patch)
tree0c1462f8bd0a33a9aa52ff3d2f0cfffdac2c318e /util.lua
parentbc2179e07b2abf01491a295ed067af9c41b387af (diff)
downloadlua_async-5c5c5d17f469a686375aeff95b3ccb9c2ee9767b.tar.xz
Implement yield() using a promise and setImmediate
Diffstat (limited to 'util.lua')
-rw-r--r--util.lua8
1 files changed, 3 insertions, 5 deletions
diff --git a/util.lua b/util.lua
index 852b933..e7c6cbf 100644
--- a/util.lua
+++ b/util.lua
@@ -1,9 +1,7 @@
function lua_async.yield()
- local co = assert(coroutine.running(), "yield called outside of an async function")
-
- setTimeout(lua_async.resume, 0, co)
-
- coroutine.yield()
+ await(Promise(function(resolve)
+ setImmediate(resolve)
+ end))
end
function lua_async.kill_thread()