local freeThread: thread? local function run(thread: thread, fn: (T...) -> (), ...: T...) freeThread = nil fn(...) freeThread = thread end local function runner() while true do run(coroutine.yield()) end end local function spawn(callback: (T...) -> (), ...: T...) local thread = freeThread or task.spawn(runner) task.spawn(thread, thread, callback, ...) end local function call(callback: (T...) -> (), ...: T...) callback(...) end return (if task then spawn else call) :: typeof(spawn)