Skip to main content

Sequent

Sequent is a signal-like structure that executes connections in a serial nature. Each connection must fully complete before the next is run. Connections can be prioritized and cancelled.

local sequent = Sequent.new()

sequent:Connect(
	function(event)
		print("Got value", event.Value)
		event:Cancel()
	end,
	Sequent.Priority.Highest,
)

sequent:Connect(
	function(event)
		print("This won't print!")
	end,
	Sequent.Priority.Lowest,
)

sequent:Fire("Test")

Types​

SequentConnection​

interface SequentConnection {
Connected: boolean
Disconnect: (self: SequentConnection) → ()
}
print(sequent.Connected)
sequent:Disconnect()

SequentEvent<T>​

interface SequentEvent<T> {
Value: T
Cancellable: boolean
Cancel: (self: SequentEvent<T>) → ()
}

Events are passed to connected callbacks when sequents are fired. Events can be cancelled as well, which prevents the event from propagating to other connected callbacks during the same firing. This can be used to sink events if desired.

sequent:Connect(function(event)
	print(event.Value)
	event:Cancel()
end, 0)

Priority​

interface Priority {
Highest: math.huge
High: 1000
Normal: 0
Low: -1000
Lowest: -math.huge
}
sequent:Connect(fn, Sequent.Priority.Highest)

Functions​

new​

Sequent.new(cancellable: boolean?) → Sequent<T>

Constructs a new Sequent. If cancellable is true, then connected handlers can cancel event propagation.

Fire​

This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. Yields
Sequent:Fire(value: T) → ()

Fires the Sequent with the given value.

This method will yield until all connections complete. Errors will bubble up if they occur within a connection.

IsFiring​

Sequent:IsFiring() → boolean

Returns true if the Sequent is currently firing.

Connect​

Sequent:Connect(
callback: (...unknown) → (),
priority: number
) → SequentConnection

Connects a callback to the Sequent, which gets called anytime Fire is called.

The given priority indicates the firing priority of the callback. Higher priority values will be run first. There are a few defaults available via Sequent.Priority.

Once​

Sequent:Once(
callback: (...unknown) → (),
priority: number
) → SequentConnection

Once() is the same as Connect(), except the connection is automatically disconnected after being fired once.

Cancel​

Sequent:Cancel() → ()

Cancels a currently-firing Sequent.

Destroy​

Sequent:Destroy() → ()

Cleans up the Sequent. All connections are disconnected. The Sequent is cancelled if it is currently firing.

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Constructs a new Sequent. If `cancellable` is `true`, then\nconnected handlers can cancel event propagation.",
            "params": [
                {
                    "name": "cancellable",
                    "desc": "",
                    "lua_type": "boolean?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Sequent<T>\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 123,
                "path": "modules/sequent/init.luau"
            }
        },
        {
            "name": "Fire",
            "desc": "Fires the Sequent with the given value.\n\nThis method will yield until all connections complete. Errors will\nbubble up if they occur within a connection.",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "returns": [],
            "function_type": "method",
            "yields": true,
            "source": {
                "line": 145,
                "path": "modules/sequent/init.luau"
            }
        },
        {
            "name": "IsFiring",
            "desc": "Returns `true` if the Sequent is currently firing.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 222,
                "path": "modules/sequent/init.luau"
            }
        },
        {
            "name": "Connect",
            "desc": "Connects a callback to the Sequent, which gets called anytime `Fire`\nis called.\n\nThe given `priority` indicates the firing priority of the callback. Higher\npriority values will be run first. There are a few defaults available via\n`Sequent.Priority`.",
            "params": [
                {
                    "name": "callback",
                    "desc": "",
                    "lua_type": "(...unknown) -> ()"
                },
                {
                    "name": "priority",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "SequentConnection\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 234,
                "path": "modules/sequent/init.luau"
            }
        },
        {
            "name": "Once",
            "desc": "`Once()` is the same as `Connect()`, except the connection is automatically\ndisconnected after being fired once.",
            "params": [
                {
                    "name": "callback",
                    "desc": "",
                    "lua_type": "(...unknown) -> ()"
                },
                {
                    "name": "priority",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "SequentConnection\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 262,
                "path": "modules/sequent/init.luau"
            }
        },
        {
            "name": "Cancel",
            "desc": "Cancels a currently-firing Sequent.",
            "params": [],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 279,
                "path": "modules/sequent/init.luau"
            }
        },
        {
            "name": "Destroy",
            "desc": "Cleans up the Sequent. All connections are disconnected. The Sequent is cancelled\nif it is currently firing.",
            "params": [],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 308,
                "path": "modules/sequent/init.luau"
            }
        }
    ],
    "properties": [],
    "types": [
        {
            "name": "SequentConnection",
            "desc": "```lua\nprint(sequent.Connected)\nsequent:Disconnect()\n```",
            "fields": [
                {
                    "name": "Connected",
                    "lua_type": "boolean",
                    "desc": ""
                },
                {
                    "name": "Disconnect",
                    "lua_type": "(self: SequentConnection) -> ()",
                    "desc": ""
                }
            ],
            "source": {
                "line": 20,
                "path": "modules/sequent/init.luau"
            }
        },
        {
            "name": "SequentEvent<T>",
            "desc": "Events are passed to connected callbacks when sequents are fired. Events\ncan be cancelled as well, which prevents the event from propagating to\nother connected callbacks during the same firing. This can be used to\nsink events if desired.\n\n```lua\nsequent:Connect(function(event)\n\tprint(event.Value)\n\tevent:Cancel()\nend, 0)\n```",
            "fields": [
                {
                    "name": "Value",
                    "lua_type": "T",
                    "desc": ""
                },
                {
                    "name": "Cancellable",
                    "lua_type": "boolean",
                    "desc": ""
                },
                {
                    "name": "Cancel",
                    "lua_type": "(self: SequentEvent<T>) -> ()",
                    "desc": ""
                }
            ],
            "source": {
                "line": 44,
                "path": "modules/sequent/init.luau"
            }
        },
        {
            "name": "Priority",
            "desc": "```lua\nsequent:Connect(fn, Sequent.Priority.Highest)\n```",
            "fields": [
                {
                    "name": "Highest",
                    "lua_type": "math.huge",
                    "desc": ""
                },
                {
                    "name": "High",
                    "lua_type": "1000",
                    "desc": ""
                },
                {
                    "name": "Normal",
                    "lua_type": "0",
                    "desc": ""
                },
                {
                    "name": "Low",
                    "lua_type": "-1000",
                    "desc": ""
                },
                {
                    "name": "Lowest",
                    "lua_type": "-math.huge",
                    "desc": ""
                }
            ],
            "source": {
                "line": 80,
                "path": "modules/sequent/init.luau"
            }
        }
    ],
    "name": "Sequent",
    "desc": "Sequent is a signal-like structure that executes connections in a serial nature. Each\nconnection must fully complete before the next is run. Connections can be prioritized\nand cancelled.\n\n```lua\nlocal sequent = Sequent.new()\n\nsequent:Connect(\n\tfunction(event)\n\t\tprint(\"Got value\", event.Value)\n\t\tevent:Cancel()\n\tend,\n\tSequent.Priority.Highest,\n)\n\nsequent:Connect(\n\tfunction(event)\n\t\tprint(\"This won't print!\")\n\tend,\n\tSequent.Priority.Lowest,\n)\n\nsequent:Fire(\"Test\")\n```",
    "source": {
        "line": 116,
        "path": "modules/sequent/init.luau"
    }
}