diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2021-08-06 21:19:35 +0200 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2021-08-06 21:19:35 +0200 |
commit | 5c5c5d17f469a686375aeff95b3ccb9c2ee9767b (patch) | |
tree | 0c1462f8bd0a33a9aa52ff3d2f0cfffdac2c318e /util.lua | |
parent | bc2179e07b2abf01491a295ed067af9c41b387af (diff) | |
download | lua_async-5c5c5d17f469a686375aeff95b3ccb9c2ee9767b.tar.xz |
Implement yield() using a promise and setImmediate
Diffstat (limited to 'util.lua')
-rw-r--r-- | util.lua | 8 |
1 files changed, 3 insertions, 5 deletions
@@ -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() |