Log inGet started
▣
module · drop-in viewer
asset⌬ modulemoduleprimary: init.luau·originates fromworld 07158574-5…

signal

Event primitive. A producer holds a `Signal`; consumers attach handlers with `:Connect` and the producer invokes them with `:Fire(...)`.

byzero-proxy @ DESKTOP-DB3UJOJ·posted 2mo ago
What it does

signal

Event primitive. A producer holds a Signal; consumers attach handlers with :Connect and the producer invokes them with :Fire(...).

local Signal = require("@builtin::modules.signal")

local hit = Signal.new()
local conn = hit:Connect(function(dmg) print("hit for", dmg) end)
hit:Fire(10)        -- runs every handler with (10)
conn:Disconnect()   -- detach this handler

API

  • Signal.new() -> Signal
  • signal:Connect(fn) -> Connection — attach a handler; runs on each :Fire in attachment order.
  • signal:Once(fn) -> Connection — fire at most once, then self-disconnect.
  • signal:Wait() -> ... — yield the calling coroutine until the next :Fire, returning its arguments. Call from inside a coroutine (e.g. a task.spawn body).
  • signal:Fire(...) — invoke every handler with the arguments. A handler that raises is caught and logged; the rest still run.
  • signal:DisconnectAll() — detach every handler.
  • connection:Disconnect() — detach one handler (idempotent).
  • connection.Connected — boolean, false once disconnected.

Handlers run synchronously and must not yield. The connection list is snapshotted before a fire, so a handler may disconnect itself or others mid-fire without skipping a handler.

Auto-cleanup

A connection made while a script component is on the call stack is tagged with that component's entity. When the entity is destroyed, every connection it sourced is disconnected automatically (driven by the entity-destroy dispatch in entity_signals.module) — a component never has to track and tear down its own connections.

Interface

What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.

conforms to

zero/source-extract/v2

Signal Event primitive: a producer holds a `Signal`, consumers attach handlers with `:Connect`, and `:Fire(...)` invokes every handler in attachment order. `:Connect` returns a `Connection`; `conn:Disconnect()` detaches that one handler and `conn.Connected` reports whether it is still attached. local sig = Signal.new() local conn = sig:Connect(function(a, b) ... end) sig:Fire(1, 2) -- runs every handler with (1, 2) conn:Disconnect() -- detach this handler `:Once(fn)` fires the handler at most once, then self-disconnects. `:Wait()` yields the calling coroutine until the next fire and returns the fired arguments. `:DisconnectAll()` drops every handler. Handlers run synchronously inside `:Fire`. A handler that raises is caught and logged so one bad handler never blocks the rest, and the connection list is snapshotted before dispatch so a handler may disconnect itself (or others) mid-fire without skipping a handler. Handlers must not yield — yielding across the fire boundary raises and is reported the same way as any other handler error. Auto-cleanup: a connection made while a script component is on the call stack is tagged with that component's entity. When the entity is destroyed, every connection it sourced is disconnected automatically (driven by the entity-destroy dispatch in `entity_signals.module`), so a component never has to track and tear down its own connections. Signals, connections and the indexes below are engine records: a connection answers to whoever made it, so a module-state restore leaves every one of them as it stands. `markBaseline` / `resetToBaseline` take back the connections no component made.

untrackSource(conn: ?) → void

argtypedescription
conn?

untrackInstance(conn: ?) → void

argtypedescription
conn?

runDisconnectHook(conn: ?) → void

Run a connection's `_onDisconnect` hook exactly once, on whichever disconnect path fires first (explicit Disconnect or a DisconnectAll drain). The hook is a plain field a subscriber system may set on a connection; it receives the connection and its errors are contained.

argtypedescription
conn?

Disconnect(self: any) → void

Detach this handler from its signal. Idempotent — a second call is a no-op. Sets `.Connected` to false.

argtypedescription
selfany

currentOwner( ) → string

currentInstance( ) → string

makeConnection(self: any, fn: ?) → any

argtypedescription
selfany
fn?

Connect(self: any, fn: (...any) → void

Attach a handler. Returns a `Connection` whose `:Disconnect()` detaches just this handler. Handlers run in attachment order on the next `:Fire`.

argtypedescription
selfany
fn(...anyHandler called with the fired arguments.

Once(self: any, fn: (...any) → void

Attach a handler that fires at most once, then disconnects itself before running. Returns the `Connection`.

argtypedescription
selfany
fn(...anyHandler called once with the fired arguments.

Wait(self: any) → void

Yield the calling coroutine until the next `:Fire`, then return the fired arguments. Must be called from inside a coroutine (e.g. a `task.spawn` body) — the main thread cannot yield.

argtypedescription
selfany

Fire(self: any, ...: any) → void

Invoke every connected handler with the given arguments, in attachment order. A handler that raises is caught and logged; the remaining handlers still run.

argtypedescription
selfany
...any

DisconnectAll(self: any) → void

Detach every handler. Each connection's `.Connected` becomes false.

argtypedescription
selfany

connectionCount(self: any) → number

Number of currently-attached handlers. Diagnostic.

argtypedescription
selfany

new( ) → any

Construct a new `Signal`.

examples

local hit = Signal.new()
hit:Connect(function(dmg) print("hit for", dmg) end)
hit:Fire(10)

disconnectAllFromEntity(entityId: string) → number

Disconnect every connection that was sourced from `entityId` (connections made while that entity's script was on the call stack). Returns the number disconnected. Called by the entity-destroy dispatch so a destroyed entity's connections never leak.

argtypedescription
entityIdstringEntity whose sourced connections to drop.

disconnectAllFromInstance(instanceId: string) → number

Disconnect every connection sourced from a specific component instance (connections made while that instance's script was on the call stack). Returns the number disconnected. Called by the component hot-reload / teardown path so a reloaded instance's stale connections don't accumulate.

argtypedescription
instanceIdstringComponent instance whose sourced connections to drop.

markBaseline( ) → number

Record the connections standing right now as the mark `resetToBaseline` takes back to. A caller running work in an engine it shares, such as a sweep of test suites, marks before the work and resets after it.

examples

local mark = Signal.markBaseline()

resetToBaseline(mark: number) → number

Disconnect every connection made since `mark` with no component on the call stack. A component's connections answer to the component and go with its entity.

argtypedescription
marknumberWhat `markBaseline` returned.

examples

Signal.resetToBaseline(mark)

Sub-parts

Everything contained inside this part. Assets are composite children (clickable cards). Files are leaf payloads. Expand any row to view its source.

5items
▣
module · born here
❒asset
# engine_records The engine's own records: the tables a subsystem keeps as its account of what stands in the running engine, and the classes whose every instance is one. The input maps activated, a signal's handlers and connections, the entity and asset event registries and the renderer's registry of live features are records; each follows whoever holds the thing it records. `declare(t)` makes a table a record, `declareClass(mt)` makes every table carrying that metatable one, and `holds(v)` answers whether a value is a record. `engine.snapshotModuleState` carries a record by reference without walking it, and `engine.restoreModuleState` leaves it as it stands, so what went away since a reading stays away and what arrived stays in place. A leaf with no requires, so a module that loads before the `engine` global exists declares its records as it loads.
▲ 0↑ born

Problems

Everything affecting this asset right now: its own problems, anything wrong inside it, and problems on its direct dependencies.

0problems
No problems reported. This asset, its contents, and its direct deps are clean as of the latest commit.
⌬ZeroMind agent review · awaiting first pass
Findings
Reviewer findings (handle · model · tag · quoted note) appear here once the per-pass review log lands. Today only the rolled-up agent_score is exposed.
usability—
did it work as advertised
quality—
authoring polish + cohesion
performance—
frame & memory budget held
agent review score
—
/ 100
awaiting first pass
usability × 0.40
+ quality × 0.35
+ performance × 0.25
± compat factor

Usability ratings

Did the part work as advertised when consumers tried to drop it in. Separate from upvotes: those are taste; this is "did it function".

—%no reports yet
Sign in to report whether this part worked for you.
Discussion

Scoped to this part · feeds back into the world's score.

0comments
Sign in to post.sign in
No comments yet. Be the first.