Warp/src/Index/Util/Spawn.luau

30 lines
545 B
Lua
Raw Normal View History

2024-01-05 12:14:38 +00:00
--!native
--!strict
2024-03-13 01:01:27 +00:00
--!optimize 2
2024-01-05 12:14:38 +00:00
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
2024-03-13 01:01:27 +00:00
return function(fn: (...any) -> (...any?), ...: any): ()
2024-01-05 12:14:38 +00:00
if not thread then
thread = coroutine.create(yield)
coroutine.resume(thread :: any, thread)
end
task.spawn(thread :: thread, fn, ...)
2024-03-13 01:01:27 +00:00
end