Pcall infinitely yields with coroutines

pcall will infinitely yield when using coroutines. See code below to repro. Everything prints fine, including Yield finished, but Finished yield test will never get printed. This just started happening recently.

local function Yield()
	print("Starting yield function")
		
	local Thread = coroutine.running()
	
	delay(1, function()
		print("Resuming")
		coroutine.resume(Thread)	
	end)
	
	print("Yielding")
	coroutine.yield()
	
	print("Yield finished")
end
	
print("Starting yield test")
pcall(Yield)
print("Finished yeild test")

I am guessing that the pcall failed at such a level that the print did not get processed.
Perhaps code the pcall to get its results and only do the print if the pcall was successful.

Workaround: add a wait() after coroutine.yield() to return the thread to the roblox scheduler, which then is able to resume the pcall.

Similar bug: Coroutine.resume() bug while used in RemoteFunction & BindableFunction - #3 by FieryEvent

This appears to be the same as: Pcall/ypcall don't work with coroutine resume
Bindable events work fine though

local function Yield()
	local bind = Instance.new("BindableEvent")
	print("Starting yield function")
	local Thread = coroutine.running()
	delay(1, function()
		print("Resuming")
		bind:Fire()
	end)
	print("Yielding")
	bind.Event:Wait()
	print("Yield finished")
end
print("Starting yield test")
pcall(Yield)
print("Finished yeild test")
1 Like