Add async sleep function llscript.sleep
Tapple Gao
An async sleep function is probably very handy for lua scripts that are written entirely around coroutines. I haven't yet needed it myself, but, I also haven't yet written a simulation script. It might be equivalent to one of these:
function llscript.sleep(time: number)
-- async sleep. Does not pause event loop
local thread = coroutine.running()
assert(thread, "Must be called from a coroutine")
LLTimers:once(time, function() coroutine.resume(thread) end)
coroutine.yield()
end
or
function llscript.sleep(time: number)
-- async sleep. Does not pause event loop if called from a coroutine
local thread = coroutine.running()
if thread then
LLTimers:once(time, function() coroutine.resume(thread) end)
coroutine.yield()
else
ll.Sleep(number)
end
end
Log In