@antiraid-ext/signal
API reference for @antiraid-ext/signal
@antiraid-ext/signal
Types
Identity
Raw Type
type Identity<T> = {
fire: (self: Identity<T>, ...: T) -> (),
connect: (self: Identity<T>, callback: (...: T) -> ()) -> () -> (),
once: (self: Identity<T>, callback: (...: T) -> ()) -> () -> (),
wait: (self: Identity<T>) -> T,
disconnectAll: (self: Identity<T>) -> (),
delete: (self: Identity<T>) -> ()
}
Prop | Type | Description |
---|---|---|
fire | - | |
connect | - | |
once | - | |
wait | - | |
disconnectAll | (self) -> () | - |
delete | (self) -> () | - |
Functions
deletedSignalError
Function Signature
function deletedSignalError() end
run
Function Signature
function run<T>(func: (...: T) -> (), ...: T) end
Generics
T
This generic is unconstrained and can be any type
Arguments
func
Function Signature
func: (...: T) -> ()
Arguments
...
T...
...
T...
yieldLoop
Function Signature
function yieldLoop() end
constructor
[=[ @class signal
The main class for this package. It is actually just an array with a metatable! Constructed with: ```lua local signal = require(...)
signal() ``` ]=]
Function Signature
--[=[
@class signal
The main class for this package. It is actually just an array with a metatable! Constructed with:
\`\`\`lua
local signal = require(...)
signal()
\`\`\`
]=]
function constructor<T>() -> InternalIdentity<T> end
Generics
T
This generic is unconstrained and can be any type
Returns
ret1
InternalIdentity<T...>
signal.connect
[=[ @method connect @within signal
Connects a function to the signal. This will be called whenever the signal is fired. Connections can be "disconnected" (they won't be called when the signal is fired) by calling the function that they return. ```lua local sig = signal()
-- You can connect a function like this sig:connect(function(text) print(text) end)
-- You can also directly connect the function like this. sig:connect(print)
-- Will print twice, because two connections. sig:fire("Hello, world!") ```
You shouldn't connect the same function twice. This is because the function is used as a reference to disconnect when disconnecting later. While it might work for simple or specialized cases, you may find that it doesn't work as expected in some cases.
Connections will be ran in order of connection.
It's also worth noting that disconnecting is not an optimal operation, as it will shift the array. If you have a lot of connections to a single signal, you should avoid frequent disconnections.
@param callback (T...) -> () @return () -> () ]=]
Function Signature
--[=[
@method connect
@within signal
Connects a function to the signal. This will be called whenever the signal is fired.
Connections can be "disconnected" (they won't be called when the signal is fired) by calling the function that they return.
\`\`\`lua
local sig = signal()
-- You can connect a function like this
sig:connect(function(text)
print(text)
end)
-- You can also directly connect the function like this.
sig:connect(print)
-- Will print twice, because two connections.
sig:fire("Hello, world!")
\`\`\`
You shouldn't connect the same function twice. This is because the function is used as a reference to disconnect when disconnecting later.
While it *might* work for simple or specialized cases, you may find that it doesn't work as expected in some cases.
Connections will be ran in order of connection.
It's also worth noting that disconnecting is not an optimal operation, as it will shift the array. If you have a lot of connections to a single signal, you should avoid frequent disconnections.
@param callback (T...) -> ()
@return () -> ()
]=]
function signal.connect<T>(self: InternalIdentity<T>, callback: (...: T) -> ()) end
Generics
T
This generic is unconstrained and can be any type
Arguments
callback
Function Signature
callback: (...: T) -> ()
Arguments
...
T...
signal.fire
[=[ @method fire @within signal
Firing a signal will run all connections in order, while using thread reusage. [You can find more on this optimization here](https://devforum.roblox.com/t/thread-reuse-how-it-works-why-it-works/1999166).
You should note these things about thread reusage:
- You cannot rely on the thread being different, or the same consistently.
- The above means that certain "no-yield" implementations might not work correctly in connections.
- If you have a lot of connections, you should avoid yielding in said connections. Yielding forces a new thread to be spawned, which isn't optimal, but it's still okay.
@param data ... @return void ]=]
Function Signature
--[=[
@method fire
@within signal
Firing a signal will run all connections in order, while using thread reusage.
[You can find more on this optimization here](https://devforum.roblox.com/t/thread-reuse-how-it-works-why-it-works/1999166).
You should note these things about thread reusage:
- You cannot rely on the thread being different, or the same consistently.
- The above means that certain "no-yield" implementations might not work correctly in connections.
- If you have a lot of connections, you should avoid yielding in said connections. Yielding forces a new thread to be spawned, which isn't optimal, but it's still okay.
@param data ...
@return void
]=]
function signal.fire<T>(self: InternalIdentity<T>, ...: T) end
Generics
T
This generic is unconstrained and can be any type
Arguments
...
T...
signal.once
[=[ @method once @within signal
Connects to a signal, and disconnects after the first time it is fired. You can still disconnect the connection before it is fired.
@param callback (T...) -> () @return () -> () ]=]
Function Signature
--[=[
@method once
@within signal
Connects to a signal, and disconnects after the first time it is fired.
You can still disconnect the connection before it is fired.
@param callback (T...) -> ()
@return () -> ()
]=]
function signal.once<T>(self: InternalIdentity<T>, callback: (...: T) -> ()) end
Generics
T
This generic is unconstrained and can be any type
Arguments
callback
Function Signature
callback: (...: T) -> ()
Arguments
...
T...
signal.wait
[=[ @method wait @within signal
Yields the current thread until the signal is fired, and returns the arguments passed. Will raise an error if the thread is resumed before the signal is fired.
@return T... ]=]
Function Signature
--[=[
@method wait
@within signal
Yields the current thread until the signal is fired, and returns the arguments passed.
Will raise an error if the thread is resumed before the signal is fired.
@return T...
]=]
function signal.wait<T>(self: InternalIdentity<T>) -> T end
Generics
T
This generic is unconstrained and can be any type
Returns
ret1
T...
signal.disconnectAll
[=[ @method disconnectAll @within signal
Disconnects all connections to the signal. This is an efficient operation, utilizing `table.clear`. ]=]
Function Signature
--[=[
@method disconnectAll
@within signal
Disconnects all connections to the signal. This is an efficient operation, utilizing \`table.clear\`.
]=]
function signal.disconnectAll<T>(self: InternalIdentity<T>) end
Generics
T
This generic is unconstrained and can be any type
signal.delete
[=[ @method delete @within signal
Disconnects all connections to the signal, and renders the signal unusable. While this technically isn't required or needed for memory concerns, you might want to use this when you're working with others.
This will prevent and raise an error upon any attempts to use the signal, which is useful for debugging & catching leaks. ]=]
Function Signature
--[=[
@method delete
@within signal
Disconnects all connections to the signal, and renders the signal unusable.
While this technically isn't required or needed for memory concerns, you might want to use this when you're working with others.
This will prevent and raise an error upon any attempts to use the signal, which is useful for debugging & catching leaks.
]=]
function signal.delete<T>(self: InternalIdentity<T>) -> () end
Generics
T
This generic is unconstrained and can be any type
Last updated on