Hi,
So in my signal implementation I have run into an issue with the :Wait method. If the signal is dead, and after its death its :Wait method is called, I want it to just close the running thread. Should I yield the thread infinitely, I will have a memory leak because the thread is in a suspended state, so it is expected to resume at some point. What I want is to kill the thread in which the signal:Wait method is called.
I’ve tried using task.cancel
and coroutine.close
on coroutine.running()
, however in both cases it produces an error.
Using task lib gives me cannot cancel thread
Using coroutine lib gives me cannot close running coroutine
Any ideas as to how I’d approach it?
Here’s what I have currently:
function signal:Wait()
assert(self.IsSignal, 'Attempt to call member function Signal.Wait on a non-signal value!')
if self._dead then
task.cancel(coroutine.running())
end
table.insert(self._yields, coroutine.running())
return coroutine.yield()
end
Currently I’m thinking of making a boilerplate solution by deferring a task.cancel call on the active thread, then yielding the active thread but I really don’t know if this is the right way to go about doing this (ie. task.defer(task.cancel, coroutine.running()); coroutine.yield()
)
Thanks for any insight and help.