Join the watcher with client
(ctx context.Context, client Client, recursive bool)
| 113 | |
| 114 | // Join the watcher with client |
| 115 | func (w *Watcher) Join(ctx context.Context, client Client, recursive bool) *probe.Error { |
| 116 | wo, err := client.Watch(ctx, WatchOptions{ |
| 117 | Recursive: recursive, |
| 118 | Events: []string{"put", "delete", "bucket-creation", "bucket-removal"}, |
| 119 | }) |
| 120 | if err != nil { |
| 121 | return err |
| 122 | } |
| 123 | |
| 124 | w.o = append(w.o, wo) |
| 125 | |
| 126 | // join monitoring waitgroup |
| 127 | w.wg.Add(1) |
| 128 | |
| 129 | // wait for events and errors of individual client watchers |
| 130 | // and sent then to eventsChan and errorsChan |
| 131 | go func() { |
| 132 | defer w.wg.Done() |
| 133 | |
| 134 | for { |
| 135 | select { |
| 136 | case <-wo.DoneChan: |
| 137 | return |
| 138 | case events, ok := <-wo.Events(): |
| 139 | if !ok { |
| 140 | return |
| 141 | } |
| 142 | w.EventInfoChan <- events |
| 143 | case err, ok := <-wo.Errors(): |
| 144 | if !ok { |
| 145 | return |
| 146 | } |
| 147 | |
| 148 | w.ErrorChan <- err |
| 149 | } |
| 150 | } |
| 151 | }() |
| 152 | |
| 153 | return nil |
| 154 | } |