-- Thread utilities


local SpawnBindable = Instance.new("BindableEvent")

function FastSpawn(fn, ...)
	coroutine.wrap(function(...)
		SpawnBindable.Event:Wait()
		fn(...)
	end)(...)
	
	SpawnBindable:Fire()
end

function YieldThread()
	-- needed a way to first call coroutine.yield(), and then call SpawnBindable.Event:Wait()
	-- but return what coroutine.yield() returned. This is kinda ugly, but the only other
	-- option was to create a temporary table to store the results, which I didn't want to do
	
	return (function(...) SpawnBindable.Event:Wait() return ... end)(coroutine.yield())
end

function ResumeThread(thread, ...)
	coroutine.resume(thread, ...)
	SpawnBindable:Fire()
end
