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
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
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. YieldsSequent:
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
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
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.