mirror of
https://github.com/imezx/Warp.git
synced 2025-04-24 23:20:02 +00:00
30 lines
525 B
Lua
30 lines
525 B
Lua
|
--!native
|
||
|
--!strict
|
||
|
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): ()
|
||
|
if not thread then
|
||
|
thread = coroutine.create(yield)
|
||
|
coroutine.resume(thread :: any, thread)
|
||
|
end
|
||
|
task.spawn(thread :: thread, fn, ...)
|
||
|
end
|