jeudi 17 mars 2022

Different ways of processing event in finite state machine (software)

I'm learning the state design pattern and curious about two ways of handling events and state transitions. My question actually has nothing to do with the pattern itself.

Given a current state 's' and event 'e', we can capture the transition as:

s' = s->event_handler(e)

In some examples, the handling stops at this point and the event is considered fully handled. In others, however, the handling does not cease after deriving the new state s'. In the latter model, the same event 'e' is sent/fed to s' again in a loop. Effectively, we have:

while (1) {
    s' = s->event_handler(e)
    if (s == s')
        break
}

This appears similar to level vs. edge triggering. The first model is like edge trigger whilst the second, level trigger. In a sense, only when the event handler no longer returns a new state is the event considered handled.

What's difference in the 2 models and their respecitve use cases? Thanks.

Aucun commentaire:

Enregistrer un commentaire