(SOLVED) Awaiting signals: coroutines or bindables?
Asked by
4 years ago Edited 4 years ago
hello everybody,
recently I attempted to create my own signal class. I noticed that other users have had two different approaches for creating Event:Wait()
; either they create a bindable and fire it along with the signal like so
02 | local self = setmetatable ( { } , Signal) |
03 | self._Yield = Instance.new(“BindableEvent”, script) |
07 | function Signal:Fire(...) |
or they use coroutine.yield
on the current thread and create a listener to resume when the signal fires
04 | local thread = coroutine.running() |
05 | local connection = Connection.new(self) |
06 | local function resume() |
07 | connection:Disconnect() |
08 | coroutine.resume(thread) |
10 | self [ connection ] = resume |
11 | return coroutine.yield() |
I went with coroutines because it was based on pure lua. I haven’t really found anything comparing the two. is one really better practice than the other?
thanks.