forked from warpfork/pogo
-
Notifications
You must be signed in to change notification settings - Fork 3
/
proc_state.go
74 lines (62 loc) · 1.71 KB
/
proc_state.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package gosh
type State int32
// we don't exactly need 32 bits, but it's often powerful to use this in a LoadInt32,
// and there's no such thing as a sub-word memory fence, so. 32 it is.
const (
/*
'Unstarted' is the state of a command that has been constructed, but execution has not yet begun.
*/
UNSTARTED State = iota
/*
'Running' is the state of a command that has begun execution, but not yet finished.
*/
RUNNING
/*
'Finished' is the state of a command that has finished normally.
The exit code may or may not have been success, but at the very least we
successfully observed that exit code.
*/
FINISHED
/*
'Panicked' is the state of a command that at some point began execution, but has encountered
serious problems.
It may not be clear whether or not the command is still running, since a panic implies we no
longer have completely clear visibility to the command on the underlying system. The exit
code may not be reliably known.
*/
PANICKED
)
/*
Returns true if the command is current running.
*/
func (state State) IsRunning() bool {
return state == RUNNING
}
/*
Returns true if the command has ever been started (including if the command is already finished).
*/
func (state State) IsStarted() bool {
switch state {
case RUNNING, FINISHED, PANICKED:
return true
default:
return false
}
}
/*
Returns true if the command is finished (either gracefully, or with internal errors).
*/
func (state State) IsDone() bool {
switch state {
case FINISHED, PANICKED:
return true
default:
return false
}
}
/*
Returns true if the command is finished gracefully. (A nonzero exit code may still be set.)
*/
func (state State) IsFinishedGracefully() bool {
return state == FINISHED
}