summaryrefslogtreecommitdiff
path: root/pkg/custom.go
blob: 9ed2bcaf9a7bc90b42cc4b921d6978e14086d5ea (plain)
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
package gonf

var customPromises []*CustomPromise

func init() {
	customPromises = make([]*CustomPromise, 0)
}

type CustomPromiseInterface interface {
	Promise
	Status() Status
}

type CustomPromise struct {
	promise CustomPromiseInterface
}

func MakeCustomPromise(p CustomPromiseInterface) *CustomPromise {
	return &CustomPromise{
		promise: p,
	}
}

func (c *CustomPromise) IfRepaired(p ...Promise) Promise {
	c.promise.IfRepaired(p...)
	return c
}

func (c *CustomPromise) Promise() Promise {
	customPromises = append(customPromises, c)
	return c
}

func (c *CustomPromise) Resolve() {
	c.promise.Resolve()
}

func (c CustomPromise) Status() Status {
	return c.Status()
}

func resolveCustomPromises() (status Status) {
	status = KEPT
	for _, c := range customPromises {
		if c.promise.Status() == PROMISED {
			c.Resolve()
			switch c.promise.Status() {
			case BROKEN:
				return BROKEN
			case REPAIRED:
				status = REPAIRED
			}
		}
	}
	return
}