I think you’re confused. I’ve been in this platform for nearly 8 years, I use GoodSignal, I have almost all open source libraries in possession, I understand very well what you’re on about, but you see, I’m a person that likes to stay in topic, if OP asks for something I reply with exactly what he wants, I don’t consider x better than y because it’s not what OP wants to hear about.
About the signal only working for one listener, that is already stated in the code itself as a comment in the very first lines and is designed on purpose as I don’t like having one signal for many connections, neither I like to have metatables when I’m not using metamethods.
You assumed that I do that on a daily basis when I don’t. I don’t reinvent code, I research everyday, hence my presence in the devforum.
These replies of mine are simply byproduct of the things I’ve seen. Just think about it. How would I write a signal that has nearly identical behavior to GoodSignal if I had never seen it before?
Have you considered looking into Roblox’s own personal Signal? I wonder why they are not using GoodSignal, well probably because it’s not absolute neither definitive, but another way to make signals.
This is Roblox Signal by the way:
--!strict
local types = require(script.Parent.types)
type Callback<T> = types.Callback<T>
type Subscription = types.Subscription
type Signal<T> = types.Signal<T>
type FireSignal<T> = types.FireSignal<T>
type InternalSubscription<T> = { callback: Callback<T>, unsubscribed: boolean }
local function createSignal<T>(): (Signal<T>, FireSignal<T>)
local subscriptions: { [Callback<T>]: InternalSubscription<T> } = {}
local suspendedSubscriptions = {}
local firing = false
local function subscribe(_self: Signal<T>, callback)
local subscription = {
callback = callback,
unsubscribed = false,
}
-- If the callback is already registered, don't add to the
-- suspendedConnection. Otherwise, this will disable the existing one.
if firing and not subscriptions[callback] then
suspendedSubscriptions[callback] = subscription
else
subscriptions[callback] = subscription
end
local function unsubscribe(_self: Subscription)
subscription.unsubscribed = true
subscriptions[callback] = nil
suspendedSubscriptions[callback] = nil
end
return {
unsubscribe = unsubscribe,
}
end
local function fire(value: T)
firing = true
for callback, subscription in subscriptions do
if not subscription.unsubscribed and not suspendedSubscriptions[callback] then
callback(value)
end
end
firing = false
for callback, subscription in suspendedSubscriptions do
subscriptions[callback] = subscription
end
table.clear(suspendedSubscriptions)
end
return {
subscribe = subscribe,
}, fire
end
return createSignal
RobloxSignal.rbxm (4.8 KB)
FastCastSignal.lua (5.0 KB)