### GoodSignal Thread Creation Example Source: https://github.com/data-oriented-house/lemonsignal/blob/main/docs/guide/performance.md This example demonstrates how GoodSignal can be forced to create multiple threads when asynchronous connections do not complete within the expected timeframe. ```lua local signal = GoodSignal.new() signal:Connect(function() print("sync") end) signal:Connect(function() task.wait() print("async") end) signal:Connect(function() print("sync") end) signal:Fire() -- The signal will be forced to create two threads because -- the middle connection will not return the thread in time ``` -------------------------------- ### Signal Constructors Source: https://github.com/data-oriented-house/lemonsignal/blob/main/docs/classes/signal.md Demonstrates how to create new Signal instances using `new` and `wrap`. ```APIDOC ## Constructors ### new Returns a new signal instance which can be used to connect functions. ```lua local LemonSignal = require(path.to.LemonSignal) local signal = LemonSignal.new() ``` ### wrap Returns a new signal instance which fires along with the passed RBXScriptSignal. ```lua Players.PlayerAdded:Connect(function(player) print(player, "joined, from RBXScriptSignal") end) local playerAdded = LemonSignal.wrap(Players.PlayerAdded) local connection = playerAdded:Connect(function(player) print(player, "joined, from LemonSignal") end) playerAdded:Wait() -- Player1 joins after some time passes --> Player1 joined, from RBXScriptSignal --> Player1 joined, from LemonSignal connection:Disconnect() playerAdded:Wait() -- Player2 joins after some time passes --> Player2 joined, from RBXScriptSignal connection:Reconnect() -- Now we get our hands on more API! -- Player3 joins after some time passes --> Player3 joined, from RBXScriptSignal --> Player3 joined, from LemonSignal -- It can also be used to mock Roblox event fires. playerAdded:Fire(playerAdded, Players:FindFirstChildOfClass("Player")) --> Player1 joined, from LemonSignal ``` ``` -------------------------------- ### Signal Methods Source: https://github.com/data-oriented-house/lemonsignal/blob/main/docs/classes/signal.md Detailed documentation for each method available on a Signal instance. ```APIDOC ## Methods ### Connect Connects a function to the signal and returns the [connection](../classes/connection.md). Passed variadic arguments will always be prepended to fired arguments. ```lua local signal = LemonSignal.new() local connection1 = signal:Connect(function(str: string) print(str) end) local connection2 = signal:Connect(print, "Hello") signal:Fire("world!") --> Hello world! --> world! ``` ### Once Connects a function to a signal and returns a [connection](../classes/connection.md) which disconnects on the first fire. Can be reconnected later. ```lua local signal = Signal.new() local connection = signal:Once(print, "Test:") signal:Fire("Hello world!") --> Test: Hello world! print(connection.Connected) --> false ``` ### Wait Yields the coroutine until the signal is fired and returns the fired arguments. ```lua local signal = LemonSignal.new() task.delay(1, function() signal:Fire("Hello", "world!") end) local str1, str2 = signal:Wait() print(str1) --> Hello print(str2) --> world! ``` ### Fire Fires the signal and calls all connected functions with the connection's bound arguments and the fired arguments. ```lua local signal = LemonSignal.new() local connection = signal:Connect(print, "Test:") signal:Fire("Hello world!") --> Test: Hello world! ``` ### DisconnectAll Disconnects all connections currently connected to the signal. They may be reconnected later. ```lua local signal = LemonSignal.new() local connection1 = signal:Connect(print, "First:") local connection2 = signal:Connect(print, "Second:") signal:Fire("Hello world!") --> Second: Hello world! --> First: Hello world! signal:DisconnectAll() signal:Fire("Goodbye World!") ``` ### Destroy Similar to DisconnectAll but also disconnects the RBXScriptConnection made using `.warp`. Contrary to the method's name, the signal remains usable. ```lua local signal = LemonSignal.new() local connection = signal:Connect(print, "Hello") signal:Fire("world!") --> Hello world! signal:Destroy() signal:Fire("Goodbye World!") ``` ``` -------------------------------- ### Create a New Signal Instance Source: https://github.com/data-oriented-house/lemonsignal/blob/main/docs/classes/signal.md Instantiates a new Signal object using the `new` constructor. This signal can then be used to connect functions. ```lua local LemonSignal = require(path.to.LemonSignal) local signal = LemonSignal.new() ``` -------------------------------- ### Variadic Connections with LemonSignal Source: https://github.com/data-oriented-house/lemonsignal/blob/main/docs/guide/features.md Connect functions with varargs to reuse the same function across multiple objects, promoting a flyweight pattern. Arguments passed to :Fire are appended to the connection's varargs. ```lua local signal = LemonSignal.new() local function foo(str1: string, str2: string) print(str1 .. " " .. str2) end signal:Connect(foo, "Hello") signal:Fire("world!") --> Hello world! ``` -------------------------------- ### One-Shot Connection with LemonSignal Source: https://context7.com/data-oriented-house/lemonsignal/llms.txt Use `Signal:Once` to connect a handler that automatically disconnects after the signal fires for the first time. The returned connection can be reconnected to behave as a one-shot handler again. ```lua local LemonSignal = require(game.ReplicatedStorage.LemonSignal) local onMatchStart = LemonSignal.new() -- Fire once, then auto-disconnect local cn = onMatchStart:Once(function(mapName: string) print("Match started on:", mapName) end) print(cn.Connected) --> true onMatchStart:Fire("Lava Arena") --> Match started on: Lava Arena print(cn.Connected) --> false -- The connection can be restored and will behave as Once again cn:Reconnect() onMatchStart:Fire("Ice Caves") --> Match started on: Ice Caves print(cn.Connected) --> false ``` -------------------------------- ### Connect with Variadic Arguments Source: https://context7.com/data-oriented-house/lemonsignal/llms.txt Connects a callback function to a signal, optionally prepending fixed arguments to those passed by Fire. This enables the flyweight pattern for reusing functions with different contexts. ```luau local LemonSignal = require(game.ReplicatedStorage.LemonSignal) local onDamage = LemonSignal.new() -- Plain connection local cn1 = onDamage:Connect(function(amount: number) print("Took damage:", amount) end) -- Variadic connection: "Player" is prepended to Fire's arguments local cn2 = onDamage:Connect(function(entity: string, amount: number) print(entity, "took damage:", amount) end, "Player") -- Flyweight: reuse the same function for multiple entities local function onHit(entity: string, amount: number) print(entity .. " hit for " .. amount) end local cn3 = onDamage:Connect(onHit, "Enemy") local cn4 = onDamage:Connect(onHit, "Boss") onDamage:Fire(10) --> Enemy hit for 10 --> Boss hit for 10 --> Player took damage: 10 --> Took damage: 10 print(cn1.Connected) --> true ``` -------------------------------- ### Check Connection Status Source: https://github.com/data-oriented-house/lemonsignal/blob/main/docs/classes/connection.md Demonstrates how to check the 'Connected' property of a connection object. Disconnect the connection to observe the property change. ```lua local signal = LemonSignal.new() local connection = signal:Connect(print, "Hello world!") print(connection.Connected) --> true connection:Disconnect() print(connection.Connected) --> false ``` -------------------------------- ### LemonSignal.new() Source: https://context7.com/data-oriented-house/lemonsignal/llms.txt Creates a new Signal instance. This signal can then be used to connect callbacks, wait for events, or fire signals with arguments. ```APIDOC ## LemonSignal.new() ### Description Creates and returns a new `Signal` instance. The signal starts with no connections and can immediately accept `Connect`, `Once`, `Wait`, and `Fire` calls. ### Method `LemonSignal.new()` ### Example ```lua local LemonSignal = require(ReplicatedStorage.LemonSignal) local onPlayerScored = LemonSignal.new() onPlayerScored:Connect(function(playerName: string, score: number) print(playerName .. " scored " .. score .. " points!") end) onPlayerScored:Fire("Alice", 42) --> Alice scored 42 points! ``` ``` -------------------------------- ### Connect a Function to a Signal Source: https://github.com/data-oriented-house/lemonsignal/blob/main/docs/classes/signal.md Connects a callback function to a signal. Any additional arguments passed to `Connect` will be prepended to the arguments received by the callback when the signal is fired. Returns a `Connection` object. ```lua local signal = LemonSignal.new() local connection1 = signal:Connect(function(str: string) print(str) end) local connection2 = signal:Connect(print, "Hello") signal:Fire("world!") --> Hello world! --> world! ``` -------------------------------- ### Wrap RBXScriptSignal with LemonSignal Source: https://github.com/data-oriented-house/lemonsignal/blob/main/docs/guide/features.md Convert an RBXScriptSignal into a LemonSignal using LemonSignal.wrap. This allows you to leverage the LemonSignal API on existing Roblox signals. ```lua local bindable = Instance.new("BindableEvent") local signal = LemonSignal.wrap(bindable.Event) signal:Connect(function(str: string) print("Wrapped", str) end) bindable:Fire("signal") --> Wrapped signal ``` -------------------------------- ### Create and Fire a New Signal Source: https://context7.com/data-oriented-house/lemonsignal/llms.txt Demonstrates creating a new typed signal and connecting a handler function that receives arguments. Use this for custom event notifications within your application. ```luau local ReplicatedStorage = game:GetService("ReplicatedStorage") local LemonSignal = require(ReplicatedStorage.LemonSignal) -- Create a typed signal (T... represents the argument types it will fire with) local onPlayerScored = LemonSignal.new() -- Connect a handler onPlayerScored:Connect(function(playerName: string, score: number) print(playerName .. " scored " .. score .. " points!") end) -- Fire the signal with arguments onPlayerScored:Fire("Alice", 42) --> Alice scored 42 points! ``` -------------------------------- ### Reconnect Connection Source: https://github.com/data-oriented-house/lemonsignal/blob/main/docs/classes/connection.md Demonstrates reconnecting a previously disconnected connection. Note that a ':Once' connection will disconnect again after the next signal fire. ```lua local signal = LemonSignal.new() local connection = signal:Connect(print, "Test:") signal:Fire("Hello world!") --> Test: Hello world! connection:Disconnect() signal:Fire("Goodbye world!") connection:Reconnect() signal:Fire("Hello again!") --> Test: Hello again! ``` -------------------------------- ### Wrap a Roblox RBXScriptSignal Source: https://context7.com/data-oriented-house/lemonsignal/llms.txt Wraps a native Roblox RBXScriptSignal to gain LemonSignal's extended API, including Reconnect and variadic connections. Note that Destroy() on the wrapper disconnects both LemonSignal connections and the internal RBXScriptConnection. ```luau local Players = game:GetService("Players") local LemonSignal = require(game.ReplicatedStorage.LemonSignal) -- Wrap the native PlayerAdded event local onPlayerAdded = LemonSignal.wrap(Players.PlayerAdded) -- Both the original and the wrapper fire simultaneously Players.PlayerAdded:Connect(function(player) print(player.Name, "joined (via RBXScriptSignal)") end) local cn = onPlayerAdded:Connect(function(player) print(player.Name, "joined (via LemonSignal wrapper)") end) -- Mock a fire on the wrapper (does NOT fire the original RBXScriptSignal) onPlayerAdded:Fire(Players:FindFirstChildOfClass("Player")) --> Alice joined (via LemonSignal wrapper) -- Clean up: disconnects all LemonSignal connections AND the internal RBXScriptConnection onPlayerAdded:Destroy() print(onPlayerAdded.RBXScriptConnection) --> nil ``` -------------------------------- ### Connect a Function to Fire Once Source: https://github.com/data-oriented-house/lemonsignal/blob/main/docs/classes/signal.md Connects a callback function to a signal that will only execute once. The function is automatically disconnected after the first fire. Returns a `Connection` object that can be reconnected. ```lua local signal = Signal.new() local connection = signal:Once(print, "Test:") signal:Fire("Hello world!") --> Test: Hello world! print(connection.Connected) --> false ``` -------------------------------- ### Signal:Connect(fn, ...) → Connection Source: https://context7.com/data-oriented-house/lemonsignal/llms.txt Connects a callback function to a signal. Optionally accepts variadic arguments that are prepended to the arguments passed during the `Fire` call, enabling context-specific callbacks. ```APIDOC ## Signal:Connect(fn, ...) → Connection ### Description Connects a callback function to the signal and returns a `Connection` object. Optionally, variadic arguments can be passed after `fn`; these are **prepended** to any arguments passed by `Fire`. This enables the flyweight pattern — one function shared across many connections, each with its own bound context. ### Method `Signal:Connect(fn, ...)` ### Parameters #### Path Parameters - **fn** (function) - Required - The callback function to execute when the signal is fired. - **...** (any) - Optional - Variadic arguments to prepend to the arguments passed by `Fire`. ### Returns - **Connection** - An object representing the connection, which can be used to disconnect. ### Example ```lua local LemonSignal = require(game.ReplicatedStorage.LemonSignal) local onDamage = LemonSignal.new() -- Plain connection local cn1 = onDamage:Connect(function(amount: number) print("Took damage:", amount) end) -- Variadic connection: "Player" is prepended to Fire's arguments local cn2 = onDamage:Connect(function(entity: string, amount: number) print(entity, "took damage:", amount) end, "Player") -- Flyweight: reuse the same function for multiple entities local function onHit(entity: string, amount: number) print(entity .. " hit for " .. amount) end local cn3 = onDamage:Connect(onHit, "Enemy") local cn4 = onDamage:Connect(onHit, "Boss") onDamage:Fire(10) --> Enemy hit for 10 --> Boss hit for 10 --> Player took damage: 10 --> Took damage: 10 print(cn1.Connected) --> true ``` ``` -------------------------------- ### Firing Signals with Arguments Source: https://context7.com/data-oriented-house/lemonsignal/llms.txt Use `Signal:Fire(...)` to trigger all connected handlers with specified arguments. Handlers are invoked in the reverse order of their connection. Connections can be bound with arguments that are prepended to the fired arguments. ```lua local LemonSignal = require(game.ReplicatedStorage.LemonSignal) local onEvent = LemonSignal.new() signal:Connect(print, "A:") -- connected first, called last signal:Connect(print, "B:") -- connected second, called first onEvent:Fire("hello") --> B: hello --> A: hello -- Fire with multiple arguments local onUpdate = LemonSignal.new() onUpdate:Connect(function(dt: number, frame: number) print(string.format("Frame %d, delta=%.4f", frame, dt)) end) onUpdate:Fire(0.0167, 1) --> Frame 1, delta=0.0167 ``` -------------------------------- ### Wrap an RBXScriptSignal Source: https://github.com/data-oriented-house/lemonsignal/blob/main/docs/classes/signal.md Wraps an existing RBXScriptSignal to use the Lemonsignal API. This allows for advanced features like `Wait`, `DisconnectAll`, and `Destroy` on Roblox events. The original RBXScriptSignal is also connected and will fire alongside the wrapped signal. ```lua Players.PlayerAdded:Connect(function(player) print(player, "joined, from RBXScriptSignal") end) local playerAdded = LemonSignal.wrap(Players.PlayerAdded) local connection = playerAdded:Connect(function(player) print(player, "joined, from LemonSignal") end) playerAdded:Wait() -- Player1 joins after some time passes --> Player1 joined, from RBXScriptSignal --> Player1 joined, from LemonSignal connection:Disconnect() playerAdded:Wait() -- Player2 joins after some time passes --> Player2 joined, from RBXScriptSignal connection:Reconnect() -- Now we get our hands on more API! -- Player3 joins after some time passes --> Player3 joined, from RBXScriptSignal --> Player3 joined, from LemonSignal -- It can also be used to mock Roblox event fires. playerAdded:Fire(playerAdded, Players:FindFirstChildOfClass("Player")) --> Player1 joined, from LemonSignal ``` -------------------------------- ### LemonSignal.wrap(signal: RBXScriptSignal) Source: https://context7.com/data-oriented-house/lemonsignal/llms.txt Wraps a native RBXScriptSignal, allowing it to be used with the LemonSignal API. This provides access to advanced features like variadic connections and re-connection support on existing Roblox events. ```APIDOC ## LemonSignal.wrap(signal: RBXScriptSignal) ### Description Wraps a native `RBXScriptSignal` (any Roblox engine event) so it behaves like a `LemonSignal`. Every time the original event fires, the wrapper signal fires too, forwarding all arguments. This gives access to the full LemonSignal API — including `Reconnect` and variadic connections — on any Roblox event. ### Method `LemonSignal.wrap(signal: RBXScriptSignal)` ### Parameters #### Path Parameters - **signal** (RBXScriptSignal) - Required - The native Roblox signal to wrap. ### Example ```lua local Players = game:GetService("Players") local LemonSignal = require(game.ReplicatedStorage.LemonSignal) local onPlayerAdded = LemonSignal.wrap(Players.PlayerAdded) local cn = onPlayerAdded:Connect(function(player) print(player.Name, "joined (via LemonSignal wrapper)") end) -- Mock a fire on the wrapper (does NOT fire the original RBXScriptSignal) onPlayerAdded:Fire(Players:FindFirstChildOfClass("Player")) --> Alice joined (via LemonSignal wrapper) -- Clean up: disconnects all LemonSignal connections AND the internal RBXScriptConnection onPlayerAdded:Destroy() print(onPlayerAdded.RBXScriptConnection) --> nil ``` ``` -------------------------------- ### Fire a Signal Source: https://github.com/data-oriented-house/lemonsignal/blob/main/docs/classes/signal.md Manually triggers the signal, causing all connected functions to execute with the provided arguments. Bound arguments from `Connect` are prepended. ```lua local signal = LemonSignal.new() local connection = signal:Connect(print, "Test:") signal:Fire("Hello world!") --> Test: Hello world! ``` -------------------------------- ### Signal Properties Source: https://github.com/data-oriented-house/lemonsignal/blob/main/docs/classes/signal.md Information about the properties of a Signal instance. ```APIDOC ## Properties ### RBXScriptConnection The RBXScriptConnection that gets made when using [.wrap](#wrap). It gets disconnected and removed when using [:Destroy](#Destroy). ```lua local bindable = Instance.new("BindableEvent") local signal = LemonSignal.wrap(bindable.Event) local scriptConnection = signal.RBXScriptConnection print(signal.RBXScriptConnection) --> Connection signal:Destroy() print(scriptConnection.Connected) --> false print(signal.RBXScriptConnection) --> nil ``` ``` -------------------------------- ### Signal:Fire Source: https://context7.com/data-oriented-house/lemonsignal/llms.txt Calls all connected handler functions with the provided arguments. Connections are invoked in the reverse order of their connection. ```APIDOC ## Signal:Fire(...) ### Description Calls all connected handler functions with the provided arguments. Connections are invoked in the reverse order of their connection. ### Method `Fire` ### Parameters - **...** (any) - Arguments to be passed to each connected handler function. ### Example ```lua local LemonSignal = require(game.ReplicatedStorage.LemonSignal) local onEvent = LemonSignal.new() signal:Connect(print, "A:") -- connected first, called last signal:Connect(print, "B:") -- connected second, called first onEvent:Fire("hello") -- Output: --> B: hello --> A: hello ``` ``` -------------------------------- ### Yielding Until Signal Fire with Signal:Wait() Source: https://context7.com/data-oriented-house/lemonsignal/llms.txt Use `Signal:Wait()` to pause execution until a signal fires, returning all arguments passed during the fire event. This is useful for synchronizing asynchronous operations. ```lua local LemonSignal = require(game.ReplicatedStorage.LemonSignal) local onDataLoaded = LemonSignal.new() -- Simulate async data load task.delay(2, function() onDataLoaded:Fire({ gold = 500, level = 12 }) end) -- This line yields until the signal fires local playerData = onDataLoaded:Wait() print("Gold:", playerData.gold) --> Gold: 500 print("Level:", playerData.level) --> Level: 12 -- Wait also works for multiple return values local onTeleport = LemonSignal.new() task.delay(0.5, function() onTeleport:Fire(Vector3.new(10, 0, 20), workspace.SpawnPoint) end) local position, part = onTeleport:Wait() print(position) --> 10, 0, 20 print(part) --> SpawnPoint ``` -------------------------------- ### Connection Type Definition Source: https://github.com/data-oriented-house/lemonsignal/blob/main/docs/classes/connection.md Defines the structure of a Connection object, including its Connected status and methods for Disconnect and Reconnect. ```lua type Connection = { Connected: boolean, Disconnect: (self: Connection) -> (), Reconnect: (self: Connection) -> (), } ``` -------------------------------- ### Connection:Reconnect() Source: https://context7.com/data-oriented-house/lemonsignal/llms.txt Re-inserts a previously disconnected connection into the signal's linked list, reactivating it. If the connection was created with Once, it retains its one-shot behavior. ```APIDOC ## Connection:Reconnect() ### Description Reattaches a disconnected connection to the signal's linked list, restoring it to active status. If the connection was created using `Once`, it will retain its one-shot behavior and automatically disconnect after the next signal fire. ### Method `Reconnect()` ### Parameters None ### Request Example ```lua local cn = signal:Connect(print) cn:Disconnect() cn:Reconnect() ``` ### Response #### Success Response No explicit return value. The connection is marked as connected. #### Response Example ```lua print(cn.Connected) --> true ``` ``` -------------------------------- ### Signal:Once Source: https://context7.com/data-oriented-house/lemonsignal/llms.txt Connects a handler function to a signal that will be automatically disconnected after the signal fires for the first time. The returned connection can be reconnected, and it will again disconnect after the next fire. ```APIDOC ## Signal:Once(fn, ...) → Connection ### Description Connects a handler function to a signal that will be automatically disconnected after the signal fires for the first time. The returned connection can be reconnected, and it will again disconnect after the next fire. ### Method `Once` ### Parameters - **fn** (function) - The callback function to execute when the signal fires. - **...** (any) - Arguments to be passed to the handler function when the signal fires. ### Returns - **Connection** - An object representing the connection, which can be used to manage the connection's state (e.g., check `Connected` property, call `Reconnect`). ### Example ```lua local LemonSignal = require(game.ReplicatedStorage.LemonSignal) local onMatchStart = LemonSignal.new() local cn = onMatchStart:Once(function(mapName: string) print("Match started on:", mapName) end) onMatchStart:Fire("Lava Arena") -- Output: Match started on: Lava Arena print(cn.Connected) --> false ``` ``` -------------------------------- ### Reconnect a disconnected connection in LemonSignal Source: https://context7.com/data-oriented-house/lemonsignal/llms.txt Use `Reconnect()` to reattach a previously disconnected connection, restoring its active status. If the connection was made with `Once`, it will retain its one-shot behavior. ```lua local LemonSignal = require(game.ReplicatedStorage.LemonSignal) local signal = LemonSignal.new() local persistCn = signal:Connect(print, "[persist]") local onceCn = signal:Once(print, "[once]") signal:Fire("first") --> [once] first --> [persist] first persistCn:Disconnect() signal:Fire("second") -- no output (persistCn disconnected, onceCn already fired) -- Reconnect both persistCn:Reconnect() onceCn:Reconnect() -- still behaves as Once signal:Fire("third") --> [once] third --> [persist] third print(onceCn.Connected) --> false (Once fired again, auto-disconnected) signal:Fire("fourth") --> [persist] fourth ``` -------------------------------- ### Disconnect Connection Source: https://github.com/data-oriented-house/lemonsignal/blob/main/docs/classes/connection.md Shows how to disconnect a connection from a signal. Once disconnected, the signal will no longer fire events to this connection. ```lua local signal = LemonSignal.new() local connection = signal:Connect(print, "Test:") signal:Fire("Hello world!") --> Test: Hello world! connection:Disconnect() signal:Fire("Goodbye world!") ``` -------------------------------- ### Reconnect Signal Connections Source: https://github.com/data-oriented-house/lemonsignal/blob/main/docs/guide/features.md Use :Reconnect to re-establish a disconnected signal connection with its original function and arguments. Note that :Once connections retain their behavior and will disconnect again after firing. ```lua local signal = LemonSignal.new() local connection1 = signal:Connect(function() print("Used Connect") end) local connection2 = signal:Once(function() print("Used Once") end) signal:Fire() --> Used Once --> Used Connect connection1:Disconnect() signal:Fire() -- both connections are disconnected, nothing will fire connection1:Reconnect() connection2:Reconnect() signal:Fire() --> Used Once --> Used Connect print(connection2.Connected) -- prints false, the :Once connection retains its behavior signal:Fire() --> Used Connect ``` -------------------------------- ### Reconnect Method Source: https://github.com/data-oriented-house/lemonsignal/blob/main/docs/classes/connection.md The Reconnect method re-establishes a disconnected connection to the signal. For connections set to trigger only once, they will be automatically disconnected after the next signal emission. ```APIDOC ### Reconnect Reconnects the connection to the signal again. If it's a :Once connection it will be disconnected after the next signal fire. ```lua local signal = LemonSignal.new() local connection = signal:Connect(print, "Test:") signal:Fire("Hello world!") --> Test: Hello world! connection:Disconnect() signal:Fire("Goodbye world!") connection:Reconnect() signal:Fire("Hello again!") --> Test: Hello again! ``` ``` -------------------------------- ### Define Signal Type Source: https://github.com/data-oriented-house/lemonsignal/blob/main/docs/classes/signal.md Defines the type for a generic Signal, outlining its properties and methods. ```lua type Signal = { RBXScriptConnection: RBXScriptConnection?, Connect: (self: Signal, fn: (...unknown) -> (), U...) -> Connection, Once: (self: Signal, fn: (...unknown) -> (), U...) -> Connection, Wait: (self: Signal) -> T.., Fire: (self: Signal, T...) -> (), DisconnectAll: (self: Signal) -> (), Destroy: (self: Signal) -> (), } ``` -------------------------------- ### Disconnecting All Connections Source: https://context7.com/data-oriented-house/lemonsignal/llms.txt Use `Signal:DisconnectAll()` to remove all active connections from a signal. This does not affect the ability to reconnect previously disconnected handlers. It does not disconnect connections made with `.wrap`. ```lua local LemonSignal = require(game.ReplicatedStorage.LemonSignal) local onNotify = LemonSignal.new() local cn1 = onNotify:Connect(print, "[Handler1]") local cn2 = onNotify:Connect(print, "[Handler2]") local cn3 = onNotify:Connect(print, "[Handler3]") onNotify:Fire("active") --> [Handler3] active --> [Handler2] active --> [Handler1] active onNotify:DisconnectAll() onNotify:Fire("silent") -- no output -- Connections still exist and can be reactivated cn1:Reconnect() onNotify:Fire("back") --> [Handler1] back ``` -------------------------------- ### Wait for a Signal to Fire Source: https://github.com/data-oriented-house/lemonsignal/blob/main/docs/classes/signal.md Pauses the current coroutine until the signal is fired. It then returns all arguments passed when the signal was fired. ```lua local signal = LemonSignal.new() task.delay(1, function() signal:Fire("Hello", "world!") end) local str1, str2 = signal:Wait() print(str1) --> Hello print(str2) --> world! ``` -------------------------------- ### Disconnect a single connection in LemonSignal Source: https://context7.com/data-oriented-house/lemonsignal/llms.txt Use `Disconnect()` to remove a connection from a signal. The connection can be restored later with `Reconnect()`. Calling `Disconnect` on an already-disconnected connection has no effect. ```lua local LemonSignal = require(game.ReplicatedStorage.LemonSignal) local signal = LemonSignal.new() local cn = signal:Connect(print, "Test:") signal:Fire("Hello world!") --> Test: Hello world! cn:Disconnect() signal:Fire("Goodbye world!") -- no output print(cn.Connected) --> false ``` -------------------------------- ### Access RBXScriptConnection from Wrapped Signal Source: https://github.com/data-oriented-house/lemonsignal/blob/main/docs/classes/signal.md Retrieves the underlying RBXScriptConnection when a signal is created using `.wrap`. This property is available until the signal is destroyed. ```lua local bindable = Instance.new("BindableEvent") local signal = LemonSignal.wrap(bindable.Event) local scriptConnection = signal.RBXScriptConnection print(signal.RBXScriptConnection) --> Connection signal:Destroy() print(scriptConnection.Connected) --> false print(signal.RBXScriptConnection) --> nil ``` -------------------------------- ### Destroying a Signal Instance Source: https://context7.com/data-oriented-house/lemonsignal/llms.txt Use `Signal:Destroy()` to disconnect all handlers and the internal `RBXScriptConnection` if created via `.wrap`. The signal remains functional for new connections after destruction. ```lua local LemonSignal = require(game.ReplicatedStorage.LemonSignal) local bindable = Instance.new("BindableEvent") local signal = LemonSignal.wrap(bindable.Event) local cn = signal:Connect(print, "msg:") signal:Fire("test") --> msg: test print(signal.RBXScriptConnection) --> Connection (active) signal:Destroy() print(signal.RBXScriptConnection) --> nil print(cn.Connected) --> false -- Signal is still usable after Destroy signal:Connect(print, "new:") signal:Fire("still works") --> new: still works ``` -------------------------------- ### Checking Connection State Source: https://context7.com/data-oriented-house/lemonsignal/llms.txt The `Connection.Connected` boolean property indicates if a connection is currently active. It is `true` after `Connect`, `Once`, or `Reconnect`, and `false` after `Disconnect` or a `Once` connection fires. ```lua local LemonSignal = require(game.ReplicatedStorage.LemonSignal) local signal = LemonSignal.new() local cn = signal:Connect(function() end) print(cn.Connected) --> true cn:Disconnect() print(cn.Connected) --> false cn:Reconnect() print(cn.Connected) --> true ``` -------------------------------- ### Connection Properties Source: https://github.com/data-oriented-house/lemonsignal/blob/main/docs/classes/connection.md The Connected property indicates the current state of the connection. It is a boolean value, true if connected, false otherwise. ```APIDOC ## Properties ### Connected Indicates whether the connection is connected or not. ```lua local signal = LemonSignal.new() local connection = signal:Connect(print, "Hello world!") print(connection.Connected) --> true connection:Disconnect() print(connection.Connected) --> false ``` ``` -------------------------------- ### Disconnect Method Source: https://github.com/data-oriented-house/lemonsignal/blob/main/docs/classes/connection.md The Disconnect method severs the connection to the signal. The connection can be re-established later using the Reconnect method. ```APIDOC ## Methods ### Disconnect Disconnects the connection from the signal. May be reconnected later using :Reconnect(). ```lua local signal = LemonSignal.new() local connection = signal:Connect(print, "Test:") signal:Fire("Hello world!") --> Test: Hello world! connection:Disconnect() signal:Fire("Goodbye world!") ``` ``` -------------------------------- ### Connection.Connected Source: https://context7.com/data-oriented-house/lemonsignal/llms.txt A boolean property that indicates whether a connection is currently active. It is `true` after `Connect`, `Once`, or `Reconnect`, and `false` after `Disconnect` or if a `Once` connection has fired. ```APIDOC ## Connection.Connected ### Description A boolean property that indicates whether a connection is currently active. It is `true` after `Connect`, `Once`, or `Reconnect`, and `false` after `Disconnect` or if a `Once` connection has fired. ### Property `Connected` (boolean) ### Example ```lua local LemonSignal = require(game.ReplicatedStorage.LemonSignal) local signal = LemonSignal.new() local cn = signal:Connect(function() end) print(cn.Connected) --> true cn:Disconnect() print(cn.Connected) --> false cn:Reconnect() print(cn.Connected) --> true ``` ``` -------------------------------- ### Disconnect All Signal Connections Source: https://github.com/data-oriented-house/lemonsignal/blob/main/docs/classes/signal.md Removes all active connections from the signal. Connected functions will no longer be called when the signal fires. Connections can be re-established later. ```lua local signal = LemonSignal.new() local connection1 = signal:Connect(print, "First:") local connection2 = signal:Connect(print, "Second:") signal:Fire("Hello world!") --> Second: Hello world! --> First: Hello world! signal:DisconnectAll() signal:Fire("Goodbye World!") ``` -------------------------------- ### Signal:Destroy Source: https://context7.com/data-oriented-house/lemonsignal/llms.txt Disconnects all signal connections and cleans up the internal `RBXScriptConnection` if one was created (e.g., via `.wrap`). The signal remains functional for new connections after this call. ```APIDOC ## Signal:Destroy() ### Description Disconnects all signal connections and cleans up the internal `RBXScriptConnection` if one was created (e.g., via `.wrap`). The signal remains functional for new connections after this call. ### Method `Destroy` ### Example ```lua local LemonSignal = require(game.ReplicatedStorage.LemonSignal) local bindable = Instance.new("BindableEvent") local signal = LemonSignal.wrap(bindable.Event) local cn = signal:Connect(print, "msg:") signal:Fire("test") --> msg: test signal:Destroy() -- Signal is still usable after Destroy signal:Connect(print, "new:") signal:Fire("still works") --> new: still works ``` ``` -------------------------------- ### Signal:DisconnectAll Source: https://context7.com/data-oriented-house/lemonsignal/llms.txt Disconnects all currently active connections to the signal. Connections can be reactivated later using `:Reconnect()`. ```APIDOC ## Signal:DisconnectAll() ### Description Disconnects all currently active connections to the signal. Connections can be reactivated later using `:Reconnect()`. ### Method `DisconnectAll` ### Example ```lua local LemonSignal = require(game.ReplicatedStorage.LemonSignal) local onNotify = LemonSignal.new() local cn1 = onNotify:Connect(print, "[Handler1]") local cn2 = onNotify:Connect(print, "[Handler2]") onNotify:Fire("active") -- Output: --> [Handler2] active --> [Handler1] active onNotify:DisconnectAll() onNotify:Fire("silent") -- no output cn1:Reconnect() onNotify:Fire("back") -- Output: --> [Handler1] back ``` ``` -------------------------------- ### Destroy a Signal Source: https://github.com/data-oriented-house/lemonsignal/blob/main/docs/classes/signal.md Disconnects all active connections and also removes the `RBXScriptConnection` if the signal was created using `.wrap`. The signal object itself remains usable after this method is called. ```lua local signal = LemonSignal.new() local connection = signal:Connect(print, "Hello") signal:Fire("world!") --> Hello world! signal:Destroy() signal:Fire("Goodbye World!") ``` -------------------------------- ### Signal:Wait Source: https://context7.com/data-oriented-house/lemonsignal/llms.txt Suspends the current coroutine until the signal fires, then returns the arguments with which the signal was fired. This is useful for synchronizing operations based on events. ```APIDOC ## Signal:Wait() → T... ### Description Suspends the current coroutine until the signal fires, then returns the arguments with which the signal was fired. This is useful for synchronizing operations based on events. ### Method `Wait` ### Returns - **T...** (any) - The arguments passed when the signal was fired. ### Example ```lua local LemonSignal = require(game.ReplicatedStorage.LemonSignal) local onDataLoaded = LemonSignal.new() -- Simulate async data load task.delay(2, function() onDataLoaded:Fire({ gold = 500, level = 12 }) end) -- This line yields until the signal fires local playerData = onDataLoaded:Wait() print("Gold:", playerData.gold) --> Gold: 500 print("Level:", playerData.level) --> Level: 12 ``` ``` -------------------------------- ### Connection:Disconnect() Source: https://context7.com/data-oriented-house/lemonsignal/llms.txt Removes a connection from the signal's linked list, preventing its callback from being invoked. The connection can be restored later using Reconnect(). Calling Disconnect on an already disconnected connection has no effect. ```APIDOC ## Connection:Disconnect() ### Description Detaches a single connection from the signal's linked list so its callback is no longer called when the signal fires. The connection object is preserved and can be restored with `:Reconnect()`. ### Method `Disconnect()` ### Parameters None ### Request Example ```lua local cn = signal:Connect(print, "Test:") cn:Disconnect() ``` ### Response #### Success Response No explicit return value. The connection is marked as disconnected. #### Response Example ```lua print(cn.Connected) --> false ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.