The completed state marks a task that has finished normally or has been stopped by a user. It is the final lifecycle state after Running, separating successful termination from failure. section 2.1 section 4.6.3
Treat Completed as a state with explicit transition rules:
- A running task reaches Completed when a StopTask event stops it. section 4.6.3
- A task that completes its work normally reaches Completed rather than Failed. section 2.1 section 4.6.3
- The transition map gives Completed no valid next states, making it terminal. section 4.6.3
Representing completion in Go
A Go state enum includes Completed between Running and Failed. A Task can record StartTime and FinishTime, while TaskEvent captures the resulting state and timestamp for observers. section 2.1
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 transition map to see that Running may move to Completed, while Completed cannot move onward. section 4.6.3
