A state transition map makes task-state rules explicit. It associates each current state with the states a task may validly enter, preventing unsupported jumps such as Running to Scheduled or Failed to Scheduled. section 4.6.3
The implementation uses a map from State to []State. Pending allows Scheduled; Scheduled allows Running, Completed, or Failed; terminal states allow no further transitions. ValidStateTransition asks whether a destination appears in the current state's allowed slice, while Contains performs the lookup. section 4.6.3
Checking a transition
ValidStateTransition(Scheduled, Running) returns true because Running is listed for Scheduled. ValidStateTransition(Failed, Scheduled) returns false because Failed has no allowed destinations. section 4.6.3
Listing 4.10 The stateTransitionMap map
var stateTransitionMap = map[State][]State{
Pending: []State{Scheduled},
Scheduled: []State{Scheduled, Running, Failed},
Running: []State{Running, Completed, Failed},
Completed: []State{},
Failed: []State{},
}
Inspect the compact map that encodes each task state's permitted destinations. section 4.6.3
