This module provides an optimized implementation of the signal pattern in Lua, designed for use in Roblox. It allows for efficient event handling with minimal conditionals, utilizing a linked list structure to manage connections.
- Supports multiple listeners for a single event.
- Efficient connection and disconnection methods.
- Safe error handling with
pcallfor callbacks. - Debouncing functionality to limit the firing rate of signals.
To use the Signal module in your Roblox game, place it in ReplicatedStorage or any other accessible location, then require it in your scripts.
local Signal = require(game.ReplicatedStorage:WaitForChild("Signal"))local mySignal = Signal.new()local function myCallback(...)
print("Signal fired with arguments:", ...)
end
local connection = mySignal:Connect(myCallback)mySignal:Fire("Hello", "World")connection:Disconnect()mySignal:DisconnectAll()mySignal:FireDebounced(1, "This will fire once per second.")Contributions are welcome! If you have suggestions for improvements or new features, feel free to create a pull request. Here are a few guidelines for contributing:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and test thoroughly.
- Submit a pull request with a clear description of your changes.
- Ensure to manage connections properly to avoid memory leaks.
- Utilize debouncing for frequent events to improve performance.
This project is licensed under the MIT License. See the LICENSE file for more details.