File tree 3 files changed +42
-9
lines changed
3 files changed +42
-9
lines changed Original file line number Diff line number Diff line change @@ -300,6 +300,21 @@ type contextProviderState struct {
300
300
signal chan bool
301
301
}
302
302
303
+ // Signal signals that something has changed in the provider.
304
+ //
305
+ // Note: This should only be used by fetch context providers, standard context
306
+ // providers should use Set to update the overall state.
307
+ func (c * contextProviderState ) Signal () {
308
+ // Notify the controller Run loop that a state has changed. The notification
309
+ // channel has buffer size 1 so this ensures that an update will always
310
+ // happen after this change, while coalescing multiple simultaneous changes
311
+ // into a single controller update.
312
+ select {
313
+ case c .signal <- true :
314
+ default :
315
+ }
316
+ }
317
+
303
318
// Set sets the current mapping.
304
319
func (c * contextProviderState ) Set (mapping map [string ]interface {}) error {
305
320
var err error
@@ -321,15 +336,7 @@ func (c *contextProviderState) Set(mapping map[string]interface{}) error {
321
336
return nil
322
337
}
323
338
c .mapping = mapping
324
-
325
- // Notify the controller Run loop that a state has changed. The notification
326
- // channel has buffer size 1 so this ensures that an update will always
327
- // happen after this change, while coalescing multiple simultaneous changes
328
- // into a single controller update.
329
- select {
330
- case c .signal <- true :
331
- default :
332
- }
339
+ c .Signal ()
333
340
return nil
334
341
}
335
342
Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ type ContextComm struct {
16
16
lock sync.Mutex
17
17
previous map [string ]interface {}
18
18
current map [string ]interface {}
19
+ // Signal calls onSignal.
20
+ onSignal func ()
19
21
// Set calls onSet with the new value, so tests can
20
22
// verify data from the provider.
21
23
onSet func (map [string ]interface {})
@@ -28,6 +30,16 @@ func NewContextComm(ctx context.Context) *ContextComm {
28
30
}
29
31
}
30
32
33
+ // Signal signals that something has changed in the provider.
34
+ func (t * ContextComm ) Signal () {
35
+ t .lock .Lock ()
36
+ onSignal := t .onSignal
37
+ t .lock .Unlock ()
38
+ if onSignal != nil {
39
+ onSignal ()
40
+ }
41
+ }
42
+
31
43
// Set sets the current mapping for the context.
32
44
func (t * ContextComm ) Set (mapping map [string ]interface {}) error {
33
45
var err error
@@ -45,6 +57,7 @@ func (t *ContextComm) Set(mapping map[string]interface{}) error {
45
57
if onSet != nil {
46
58
onSet (mapping )
47
59
}
60
+ t .Signal ()
48
61
49
62
return nil
50
63
}
@@ -63,6 +76,13 @@ func (t *ContextComm) Current() map[string]interface{} {
63
76
return t .current
64
77
}
65
78
79
+ // CallOnSignal sets the OnSignal callback.
80
+ func (t * ContextComm ) CallOnSignal (f func ()) {
81
+ t .lock .Lock ()
82
+ defer t .lock .Unlock ()
83
+ t .onSignal = f
84
+ }
85
+
66
86
// CallOnSet sets the OnSet callback.
67
87
func (t * ContextComm ) CallOnSet (f func (map [string ]interface {})) {
68
88
t .lock .Lock ()
Original file line number Diff line number Diff line change @@ -19,6 +19,12 @@ type FetchContextProvider interface {
19
19
type ContextProviderComm interface {
20
20
context.Context
21
21
22
+ // Signal signals that something has changed in the provider.
23
+ //
24
+ // Note: This should only be used by fetch context providers, standard context
25
+ // providers should use Set to update the overall state.
26
+ Signal ()
27
+
22
28
// Set sets the current mapping for this context.
23
29
Set (map [string ]interface {}) error
24
30
}
You can’t perform that action at this time.
0 commit comments