diff options
author | Julien Dessaux | 2024-03-23 11:29:47 +0100 |
---|---|---|
committer | Julien Dessaux | 2024-03-23 14:48:09 +0100 |
commit | 4d3e266b07ab5d2e7fd11e55006649a2fe696512 (patch) | |
tree | d0f597b8efb9d5159e7542f7a087c3a571b56e0e /pkg/custom.go | |
parent | feat(files): support creating intermediate directories (diff) | |
download | gonf-4d3e266b07ab5d2e7fd11e55006649a2fe696512.tar.gz gonf-4d3e266b07ab5d2e7fd11e55006649a2fe696512.tar.bz2 gonf-4d3e266b07ab5d2e7fd11e55006649a2fe696512.zip |
feat(custom): implemented custom promises
Diffstat (limited to 'pkg/custom.go')
-rw-r--r-- | pkg/custom.go | 56 |
1 files changed, 56 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 +} |