local js = require "js"
local window = js.global
local function sleep(delay)
local co = assert(coroutine.running(), "Should be run in a coroutine")
window:setTimeout(function()
assert(coroutine.resume(co))
end, delay*1000)
coroutine.yield()
end
coroutine.wrap(function()
print "Going to sleep now..."
sleep(3)
print "Sleep well?"
end)()
|