Skip to main content

Signal

A simple publish/subscribe architecture implementation

Functions

subscribe

Signal:subscribe(
callback(...any) → ()--

The callback to be invoked

) → () → ()--

A function that disconnects the callback

Registers a callback to be invoked when the signal is fired.

once

Signal:once(
callback(...any) → ()--

The callback to be invoked

) → () → ()--

A function that disconnects the callback

Disconnects the callback after it is invoked once. This is a useful shorthand if you only need a callback to be fired once.

fire

Signal:fire(...any) → ()

Invokes all currently subscribed callbacks. Note that, if a callback is subscribed mid-fire, it will not be invoked during that firing. Callbacks are invoked using task.spawn, so it's okay to yield inside a callback.

Show raw api
{
    "functions": [
        {
            "name": "subscribe",
            "desc": "Registers a callback to be invoked when the signal is fired.\n\n\n\t",
            "params": [
                {
                    "name": "callback",
                    "desc": "The callback to be invoked",
                    "lua_type": "(...any) -> ()"
                }
            ],
            "returns": [
                {
                    "desc": "A function that disconnects the callback",
                    "lua_type": "() -> ()"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 26,
                "path": "src/create.luau"
            }
        },
        {
            "name": "once",
            "desc": "Disconnects the callback after it is invoked once. This is a useful\nshorthand if you only need a callback to be fired once.\n\n\n\t",
            "params": [
                {
                    "name": "callback",
                    "desc": "The callback to be invoked",
                    "lua_type": "(...any) -> ()"
                }
            ],
            "returns": [
                {
                    "desc": "A function that disconnects the callback",
                    "lua_type": "() -> ()"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 50,
                "path": "src/create.luau"
            }
        },
        {
            "name": "fire",
            "desc": "Invokes all currently subscribed callbacks. Note that, if a callback is\nsubscribed mid-fire, it will not be invoked during that firing.\nCallbacks are invoked using\n[`task.spawn`](https://create.roblox.com/docs/reference/engine/libraries/task#spawn),\nso it's okay to yield inside a callback.\n\t",
            "params": [
                {
                    "name": "...",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 67,
                "path": "src/create.luau"
            }
        }
    ],
    "properties": [
        {
            "name": "_isFiring",
            "desc": "A flag indicating whether or not the signal is currently firing",
            "lua_type": "boolean",
            "private": true,
            "source": {
                "line": 12,
                "path": "src/create.luau"
            }
        }
    ],
    "types": [],
    "name": "Signal",
    "desc": "A simple publish/subscribe architecture implementation",
    "source": {
        "line": 7,
        "path": "src/create.luau"
    }
}