sendKeyNotifications sends accumulated notifications to watchers of respective keys.
()
| 1197 | |
| 1198 | // sendKeyNotifications sends accumulated notifications to watchers of respective keys. |
| 1199 | func (m *KV) sendKeyNotifications() { |
| 1200 | newNotifs := func() map[string]struct{} { |
| 1201 | // Grab and clear accumulated notifications. |
| 1202 | m.notifMu.Lock() |
| 1203 | defer m.notifMu.Unlock() |
| 1204 | |
| 1205 | if len(m.keyNotifications) == 0 { |
| 1206 | return nil |
| 1207 | } |
| 1208 | newMap := make(map[string]struct{}) |
| 1209 | m.numberOfKeyNotifications.Set(float64(len(m.keyNotifications))) |
| 1210 | notifs := m.keyNotifications |
| 1211 | m.keyNotifications = newMap |
| 1212 | return notifs |
| 1213 | } |
| 1214 | |
| 1215 | for key := range newNotifs() { |
| 1216 | m.notifyWatchersSync(key) |
| 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | // notifyWatcherSync immediately sends notification to all watchers of given key. |
| 1221 | func (m *KV) notifyWatchersSync(key string) { |