FSM (8): deferred events + richer reactive DSL — completes the upgrade
Final phase of the FSM upgrade. Extends the reactive transition DSL: - Deferred events: on.defer<E>() holds an E that arrives while in the state (instead of dropping it) and re-posts it to the mailbox after the next transition (UML deferred-event semantics). The reactive loop awaits the declared + deferred types, accumulates held envelopes, and re-injects them via Machine::repost() on exit. - Entry/exit actions: on.enter(fn) / on.exit(fn) run when the reactive state is entered / left (around the wait loop). - Internal transitions: on.event<E>().internal(fn) runs fn on E but stays in the state — no exit/enter, no transition (EventEntry gains an `internal` flag; the loop runs the action and keeps waiting). 2 new tests (Defer): a deferred Click is held in Busy and replayed in Idle after Done (with enter/exit ordering asserted); three internal Ticks accumulate with the state entered exactly once. 1002 tests (999 green, 3 skipped), ASan/UBSan clean, -Werror clean. This finishes the requested FSM upgrade: one signature-inferred State, typed Success/Failure results, multi-waiter mailbox, parallel/orthogonal regions, history states, and the deferred/internal/entry-exit DSL. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2903eca3a6
commit
4af3ee6d0c
5 files changed
+216
-7
No files matched your search
@@ -654,6 +654,15 @@ namespace Void::Fsm
|
||||
std::any{std::move(event)}});
|
||||
}
|
||||
|
||||
/// Re-post an already type-erased event (used by the reactive loop
|
||||
/// to re-inject deferred events after a transition).
|
||||
void repost(Detail::EventEnvelope env)
|
||||
{
|
||||
if (m_ctx) {
|
||||
m_ctx->post(std::move(env));
|
||||
}
|
||||
}
|
||||
|
||||
/// Fluent post: send one or several events in one call.
|
||||
/// fsm.send(Go{5}); fsm.send(Go{5}, Stop{});
|
||||
template <typename... Es> void send(Es&&... events)
|
||||
|
||||
Reference in new issue
Block a user