Start begins watching the PRD file for changes.
()
| 43 | |
| 44 | // Start begins watching the PRD file for changes. |
| 45 | func (w *Watcher) Start() error { |
| 46 | w.mu.Lock() |
| 47 | if w.running { |
| 48 | w.mu.Unlock() |
| 49 | return errors.New("watcher already running") |
| 50 | } |
| 51 | w.running = true |
| 52 | w.mu.Unlock() |
| 53 | |
| 54 | // Load the initial PRD |
| 55 | prd, err := LoadPRD(w.path) |
| 56 | if err != nil { |
| 57 | // Don't fail startup, just send error event |
| 58 | w.events <- WatcherEvent{Error: err} |
| 59 | } else { |
| 60 | w.lastPRD = prd |
| 61 | } |
| 62 | |
| 63 | // Add the file to the watcher |
| 64 | if err := w.watcher.Add(w.path); err != nil { |
| 65 | return err |
| 66 | } |
| 67 | |
| 68 | // Start the event processing goroutine |
| 69 | go w.processEvents() |
| 70 | |
| 71 | return nil |
| 72 | } |
| 73 | |
| 74 | // Stop stops watching the PRD file. |
| 75 | func (w *Watcher) Stop() { |