local outside = std.task.current()
print("outside_current_nil=" .. tostring(outside == nil))
local info_dump
local h = std.task.spawn(function()
local c = std.task.current()
return { id = c.id, name = c.name, cancelled = c.cancelled }
end, { name = "introspect" })
info_dump = h:join()
print("current_id_type=" .. type(info_dump.id))
print("current_name=" .. tostring(info_dump.name))
print("current_cancelled=" .. tostring(info_dump.cancelled))
local t0 = std.time.millis()
local h_cr = std.task.spawn(function()
coroutine.yield(30) return "coro_done"
end, { driver = "coroutine" })
local cr_val = h_cr:join()
local cr_elapsed = std.time.millis() - t0
print("coro_val=" .. tostring(cr_val))
print("coro_sleep_ok=" .. tostring(cr_elapsed >= 25))
local h_y = std.task.spawn(function()
for _ = 1, 5 do coroutine.yield() end
return 99
end, { driver = "coroutine" })
print("coro_yield_val=" .. tostring(h_y:join()))
local c1 = std.task.spawn(function() coroutine.yield(30); return "x" end, { driver = "coroutine" })
local c2 = std.task.spawn(function() coroutine.yield(30); return "y" end, { driver = "coroutine" })
local tc0 = std.time.millis()
local cx = c1:join()
local cy = c2:join()
local coro_concurrent_ms = std.time.millis() - tc0
print("coro_concurrent_ok=" .. tostring(cx == "x" and cy == "y" and coro_concurrent_ms < 55))
local ok_driver, err_driver = pcall(function()
std.task.spawn(function() return 1 end, { driver = "bogus" })
end)
print("unknown_driver_rejected=" .. tostring((not ok_driver) and tostring(err_driver):find("unknown driver") ~= nil))
local named = std.task.spawn(function()
return std.task.current().name
end, { driver = "coroutine", name = "coro_named" })
print("coro_current_name=" .. tostring(named:join()))
print("done")