PromisedSignal
An implementation of RBXScriptSignal with asynchronous callbacks.
Why PromisedSignal?
- Performs almost all the functions that RBXScriptSignal does
- Simple and comfortable
- Open sourced
How to use it?
Connection Example:
local PromisedSignal = require(game.Path.To.PromisedSignal)
local HelloPlayer = PromisedSignal.new()
HelloPlayer:Connect(function(Player)
print("Hello, " .. Player.Name .. "!")
end)
game.Players.PlayerAdded:Connect(function(Player)
HelloPlayer:FireAsync(Player) -- Hello, Username!
end)
Multi-Connections Example:
local PromisedSignal = require(game.Path.To.PromisedSignal)
local HelloPlayer = PromisedSignal.new()
HelloPlayer:Connect(function(Player)
print("Hello, " .. Player.Name .. "!")
end)
HelloPlayer:Connect(function(Player)
print("Hello, " .. Player.DisplayName.. "!")
end)
game.Players.PlayerAdded:Connect(function(Player)
HelloPlayer:FireAsync(Player) -- Hello, Username!, Hello, DisplayName!
end)
Once Example:
local PromisedSignal = require(game.Path.To.PromisedSignal)
local HelloPlayer = PromisedSignal.new()
HelloPlayer:Once(function(Player)
print("Hello, " .. Player.Name .. "!")
end)
game.Players.PlayerAdded:Connect(function(Player)
HelloPlayer:FireAsync(Player) -- Hello, Username!
task.wait(2)
HelloPlayer:FireAsync(Player) -- Nothing
end)
If you found any bugs, report them here!
Credits:
evaera’s Promise
stravant’s GoodSignal (Inspired by)