summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'pkg')
-rw-r--r--pkg/custom.go56
-rw-r--r--pkg/gonf.go8
2 files changed, 64 insertions, 0 deletions
diff --git a/pkg/custom.go b/pkg/custom.go
new file mode 100644
index 0000000..9ed2bca
--- /dev/null
+++ b/pkg/custom.go
@@ -0,0 +1,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
+}
diff --git a/pkg/gonf.go b/pkg/gonf.go
index 363a227..7a18c91 100644
--- a/pkg/gonf.go
+++ b/pkg/gonf.go
@@ -47,6 +47,14 @@ func Resolve() (status Status) {
case REPAIRED:
continue
}
+ // ----- CustomPromises ----------------------------------------
+ status = resolveCustomPromises()
+ switch status {
+ case BROKEN:
+ return BROKEN
+ case REPAIRED:
+ continue
+ }
return
}
}