Signal (plus) is a fairly personalized, all-in-one, and lightweight implementation served for communication between scripts across the same environment (client -> client and server -> server).
npm i @rbxts/signal-plus
yarn add @rbxts/signal-plus
pnpm add @rbxts/signal-plus
interface Destroyable {
Destroy(): void;
}
type Object =
| never
| undefined
| ((this: defined) => void)
| ((_: defined) => void)
| ExtractKeys<defined, () => void>
| thread
| RBXScriptConnection
| Signal
| Signal.Destroyable
| Signal.Connection;
const signal = new Signal<string>("Local_Signal");
public Is(
object?: T extends Signal.Object | Signal.Destroyable | true ? RBXScriptConnection : T | defined,
): boolean;
Returns whether or not the specified class is a valid Signal reference.
public Connect(Callback: Callback): (Callback: Callback);
Connect to the signal while awaiting on a fire to successfully load for the specified callback.
public ConnectOnce(Callback: Callback): (Callback: Callback);
Unlike the normal connect method, this will run once.
public ConnectParallel(Callback: Callback): (Callback: Callback);
Unlike the normal connect method, this will run in parallel, resulting in zero code interference.
ConnectToOnClose(Callback: Callback): (Callback: Callback);
Unlike the normal connect method, this will run when specified callback when the server's closing.
public Wait(Callback: Callback): Signal.Wait;
Wait for the connection to be fired and then return any retrieved values.
public Fire(...args: Array<defined>): void;
Fire the current signal's connections.
FireUntil(Callback: Callback, ...args: Array<defined>): void;
Fire the current signal's connections until the specified callback is reached.
OnInvoke(Callback: Callback): void;
Create a callback function that'd be activated on invoke, retrieving the function's callback.
Invoke(...args: Array<defined>): (...args: Array<defined>);
Wait until the "OnInvoke" method exists and then invoke with the necessary arguments.
public Destroy(): void;
Destroy and cleanup a Signal (making it unusable).
// Modules
import { Signal } from "@rbxts/signal-plus";
// Functions
const Table: Array<number> = [1, 2, 3];
const TableSignal = new Signal<string>("TableSignal");
function callback(currentString: string, ...args: any[]): any | undefined {
if (typeIs(currentString, "string") && currentString === "NewEntry") {
for (const arg of args) {
Table.push(arg);
}
print(Table);
}
}
TableSignal.ConnectOnce(callback);
function callback() {
while (true) {
if (Table.includes(7)) {
break;
}
task.wait(1);
}
}
TableSignal.FireUntil(callback, "NewEntry", 1);
TableSignal.Destroy();