Run watcher
(needReprint chan bool)
| 45 | |
| 46 | // Run watcher |
| 47 | func (w *Watcher) Run(needReprint chan bool) { |
| 48 | go func() { |
| 49 | f := func() { |
| 50 | w.status = "🔄" |
| 51 | needReprint <- true |
| 52 | result := w.runCommands() |
| 53 | if result { |
| 54 | w.status = "👍" |
| 55 | } else { |
| 56 | w.status = "🔴" |
| 57 | } |
| 58 | needReprint <- true |
| 59 | } |
| 60 | debounced := debounce.New(500 * time.Millisecond) |
| 61 | debounced(f) |
| 62 | for { |
| 63 | select { |
| 64 | // watch for events |
| 65 | case event := <-w.watcher.Events: |
| 66 | if event.Op.String() != "CHMOD" { |
| 67 | debounced(f) |
| 68 | } |
| 69 | |
| 70 | // watch for errors |
| 71 | case err := <-w.watcher.Errors: |
| 72 | fmt.Println("ERROR", err) |
| 73 | } |
| 74 | } |
| 75 | }() |
| 76 | } |
| 77 | |
| 78 | func (w *Watcher) runCommands() bool { |
| 79 | result := true |