diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2021-08-06 22:01:53 +0200 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2021-08-06 22:01:53 +0200 |
commit | a8361f73c9ab3c4729872ce6ac99bfa4e97cba90 (patch) | |
tree | 98e6f09b21687693a038dc290a38d1d0964386f3 /util.lua | |
parent | e6b45a401139b6ed41bf6d5612d1c80d5424b97f (diff) | |
download | lua_async-a8361f73c9ab3c4729872ce6ac99bfa4e97cba90.tar.xz |
Move resume() to util.lua
Diffstat (limited to 'util.lua')
-rw-r--r-- | util.lua | 20 |
1 files changed, 16 insertions, 4 deletions
@@ -4,16 +4,28 @@ function lua_async.yield() end)) end -function lua_async.kill_thread() - coroutine.yield(true) -end - function lua_async.sleep(ms) await(Promise(function(resolve) setTimeout(resolve, ms) end)) end +function lua_async.kill_thread() + coroutine.yield(true) +end + +function lua_async.resume(co) + local status, err = coroutine.resume(co) + + if coroutine.status(co) == "dead" or err then + lua_async.limiting.unset_limit(co) + end + + if not status then + error("Error (in async function): " .. err) + end +end + function lua_async.run() local last_time = os.clock() |