-
Notifications
You must be signed in to change notification settings - Fork 18
/
result.go
75 lines (63 loc) · 1.58 KB
/
result.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
75
package floc
import "fmt"
/*
Result identifies the result of execution.
*/
type Result int32
/*
Possible results.
*/
const (
None Result = 1
Completed Result = 2
Canceled Result = 4
Failed Result = 8
usedBitsMask Result = None | Completed | Canceled | Failed
finishedMask Result = Completed | Canceled | Failed
)
// IsNone tests if the result is None.
func (result Result) IsNone() bool {
return result == None
}
// IsCompleted tests if the result is Completed.
func (result Result) IsCompleted() bool {
return result == Completed
}
// IsCanceled tests if the result is Canceled.
func (result Result) IsCanceled() bool {
return result == Canceled
}
// IsFailed tests if the result is Failed.
func (result Result) IsFailed() bool {
return result == Failed
}
// IsFinished tests if the result is either Completed or Canceled or Failed.
func (result Result) IsFinished() bool {
return result&finishedMask != 0
}
// IsValid tests if the result is a valid value.
func (result Result) IsValid() bool {
return result == None || result == Completed || result == Canceled || result == Failed
}
// Mask constructs ResultMask with only one result masked.
func (result Result) Mask() ResultMask {
return NewResultMask(result)
}
// i32 returns the underlying value as int32.
func (result Result) i32() int32 {
return int32(result)
}
func (result Result) String() string {
switch result {
case None:
return "None"
case Completed:
return "Completed"
case Canceled:
return "Canceled"
case Failed:
return "Failed"
default:
return fmt.Sprintf("Result(%d)", result.i32())
}
}