Part of URSYS: Sri's Universal Realtime System for Javascript
A PhaseMachine maintains the idea of named "Phase Groups" consisting of "Phases", and are referred to by name. They are used to ensure a particular order of operational completion of Javascript code.
In this example, the server creates an URSYS PhaseMachine which then runs each PhaseGroup to completion in order of the definition (ur-server-init.mts)
For modules that want to participate in the URSYS PhaseMachine lifecycle, they can use HookPhase() to express their interest during runtime load (srv-comments.mts); the PhaseMachine is smart enough to queue the hooks for machines that have not yet been instantiated, so this simplifies having to worry about module dependency trees which is a pain in the ass.
PhaseMachine will eventually be enhanced with other state machine features for looping machines. It does actually implement 'enter', 'exec', and 'exit' groups...the default is 'exec' currently when not