Warp/src/Index/Util/Spawn.luau
EternityDev 563af05c62 v1.0.7
2024-03-13 08:01:27 +07:00

30 lines
No EOL
545 B
Lua

--!native
--!strict
--!optimize 2
local thread: thread? = nil
local function passer(fn, ...): ()
local hold = thread
thread = nil
fn(...)
thread = hold
end
local function yield(): never
while true do
passer(coroutine.yield())
end
end
if not thread then
thread = coroutine.create(yield)
coroutine.resume(thread :: any, thread)
end
return function(fn: (...any) -> (...any?), ...: any): ()
if not thread then
thread = coroutine.create(yield)
coroutine.resume(thread :: any, thread)
end
task.spawn(thread :: thread, fn, ...)
end