Introduction
Hello all.
I’ve recently been upgrading most of my modules in-game, and I’ve realized that I have been using BindableEvents
for my custom event module. This in itself isn’t really anything bad, but I figured I could optimize this by using a custom implementation that has no properties such as Name
, no external events such as AncestryChanged
etc - basically, have a connection class that is as bare-bone as it gets.
So, here we are!
This module is pretty much exactly the same as your default RBXScriptSignal - I’ll go over the properties in a bit. This does not have additional functionality such as a timeout property for :Wait(), you can implement that yourself easily by just wrapping this module.
Documentation
I have set up a wiki on this github link:
Example script:
local ScriptSignal = Connection.new()
local ScriptConnection = ScriptSignal.Invoked:Connect(print)
ScriptSignal:Invoke('Hello', 'World!')
delay(1, function()
ScriptSignal:Invoke('I\'ve waited 1 second for this message!')
end)
print(ScriptSignal.Invoked:Wait()) --> I've waited 1 second for this message!
print(ScriptConnection.Connected) --> true
ScriptConnection:Disconnect()
print(ScriptConnection.Connected) --> false
ScriptSignal:Invoke('This wont be invoked, because the connection was disconnected.') --> nothing
Source
The source can be found on my GitHub repository:
Efficiency
This module is actually a bit slower when creating a new connection, but when connecting callbacks to it etc, the difference is more visible.
If you find any bugs with this, make sure to report them by contacting me or posting them on this thread!