Question about coroutine.running

  1. What do you want to achieve? Keep it simple and clear!

Basically ive been experimenting with creating custom events. I wanted to implement “:Wait()” to my code but i didnt know how. So i searched for anything useful and found this article(Lua Signal Class Comparison & Optimal `GoodSignal` Class) from Stravant

  1. What is the issue? Include screenshots / videos if possible!

I noticed that he uses something like this to implement a Wait to his signal module:

function Signal:Wait()
	local Cor = coroutine.running()
	local Con = nil

	Con = self:Connect(function(...)

	return coroutine.yield()

Im a bit confused on what the “coroutine.running()” does. Does it need a coroutine as the parameter. And how does it yield the coroutine even though i dont have any coroutines in my code?

The developer hub wasnt such a big help either :frowning:

Any help is really appreciated because im a bit confused here on how it works? when i dont have any coroutines in my code :sweat_smile:

All i ever use is a task.spawn to fire the “Signal:Fire()” method in my code

Every script is contained in its own coroutine, believe it or not. This can be interfaced using coroutine/task.

print(coroutine.running()) --> thread: 0xABCDEF

Calling coroutine.running returns the thread of the script (or event handler or whatever thread is calling it)