Skip to content

NamedSignal

A signal implementation with a nice balance of ergonomics, performance, and features.

1 Richer Autofill ​

Named parameters, the key feature of NamedSignal, provides more semantic information than just the type alone.

Simply use the function type syntax to define names!

luau
local catEvent = Signal.new<<
	(name: string) -> () 
>>()

-- Parameter names and types get auto-filled!
catEvent:Connect(function(name: string)
	print(`Hi {name}!`)
end)

catEvent:Fire("Herbert") --> "Hi Herbert!"

2 Strict Typechecking ​

Catch bugs before they happen with Luau's strict typechecking.

luau
local stringAdded = Signal.new<<
	(item: string) -> () 
>>()

-- TypeError: Expected this to be 'string', but got 'number'
stringAdded:Fire(100)
                 ^^^

3 Deferred Mutations ​

Defer mutations for more predictable and consistent behavior, eliminating edge-cases.

luau
local connection: Signal.Connection

Signal:Once(function()
	connection:Disconnect() 
end)

connection = Signal:Connect(function()
	-- Some really important code that needs to run every cycle!
	print("meow")
end)

Signal:Fire() --> "meow"

Why?

Invocation is treated as sending a message to a snapshot of listeners; every listener that was connected at the time of :Fire() should get the message.

Have code that relies on immediate changes? There's an escape hatch.

Read more about deferred mutations on the dedicated page.

4 Performance ​

While NamedSignal was primarily designed with DX in mind, it's also optimized to perform well in the majority of use cases: from light signals to extremes with thousands of connections.

A minimized resumption dispatcher (also sometimes known as 'spinning threadloop'), results in a 600%+ speedup on signals with 10 connections, which along with other optimizations place NamedSignal on par with or ahead of other libraries.

Read more about optimizations and details on the dedicated page.

Interested? ​

Check out the introduction to compare with other libraries, or get straight into installation.


Synthetic Content Disclosure Score: AAA (No AI usage)

SCDS

No AI Usage

All code and documentation was written entirely by hand.