@@ -21,8 +21,22 @@ import (
21
21
22
22
// ErrSessionClosed is returned by WatchForUpdate functions when its parent Session
23
23
// object is closed.
24
+ // This error can be wrapped with additional information. Callers trying to identify this
25
+ // specific error must use errors.Is.
24
26
var ErrSessionClosed = errors .New ("parent session was closed" )
25
27
28
+ // ErrValueUpdated is returned by WatchForUpdate functions when the value being watched
29
+ // was changed or expired and needs to be retrieved again.
30
+ // This error can be wrapped with additional information. Callers trying to identify this
31
+ // specific error must use errors.Is.
32
+ var ErrValueUpdated = errors .New ("configuration must retrieve the updated value" )
33
+
34
+ // ErrWatcherNotSupported is returned by WatchForUpdate functions when the configuration
35
+ // source can't watch for updates on the value.
36
+ // This error can be wrapped with additional information. Callers trying to identify this
37
+ // specific error must use errors.Is.
38
+ var ErrWatcherNotSupported = errors .New ("value watcher is not supported" )
39
+
26
40
// ConfigSource is the interface to be implemented by objects used by the collector
27
41
// to retrieve external configuration information.
28
42
type ConfigSource interface {
@@ -67,21 +81,29 @@ type Session interface {
67
81
}
68
82
69
83
// Retrieved holds the result of a call to the Retrieve method of a Session object.
70
- type Retrieved struct {
84
+ type Retrieved interface {
71
85
// Value is the retrieved data that will be injected on the configuration.
72
- Value interface {}
73
- // WatchForUpdate must not return until one of the following happens:
86
+ Value () interface {}
87
+
88
+ // WatchForUpdate is used to monitor for updates on the retrieved value.
89
+ //
90
+ // If a watcher is not supported by the configuration store in general or for the specific
91
+ // retrieved value the WatchForUpdate must immediately return ErrWatcherNotSupported or
92
+ // an error wrapping it.
93
+ //
94
+ // When watching is supported WatchForUpdate must not return until one of the following happens:
74
95
//
75
- // 1. An update is detected for the monitored value.
96
+ // 1. An update is detected for the monitored value. In this case the function should
97
+ // return ErrValueUpdated or an error wrapping it.
76
98
//
77
99
// 2. The parent Session object is closed, in which case the method should return
78
- // ErrSessionClosed.
100
+ // ErrSessionClosed or an error wrapping it .
79
101
//
80
102
// 3. An error happens while watching for updates. The method should not return
81
103
// on first instances of transient errors, optionally there should be
82
104
// configurable thresholds to control for how long such errors can be ignored.
83
105
//
84
- // The method must return with a nil error when an update has happened to
85
- // the value monitored by the Watcher .
86
- WatchForUpdate func () error
106
+ // This method must only be called when the RetrieveEnd method of the Session that
107
+ // retrieved the value was successfully completed .
108
+ WatchForUpdate () error
87
109
}
0 commit comments