-
Notifications
You must be signed in to change notification settings - Fork 0
/
refresh.go
54 lines (46 loc) · 872 Bytes
/
refresh.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package surveillance
import (
"fmt"
)
type Refresh struct {
environment *Environment
notification *Notification
}
func NewRefresh(env *Environment, n *Notification) *Refresh {
return &Refresh{
environment: env,
notification: n,
}
}
func (c *Refresh) Run() {
startupRun := make(chan bool, 1)
startupRun <- true
for {
select {
case <-c.environment.stopRefreshing:
c.notification.Stop()
close(c.environment.stopRefreshing)
return
case <-c.notification.ChangeDetected():
c.log()
case <-startupRun:
break
}
c.reload()
c.sync()
}
}
func (c *Refresh) log() {
fmt.Println("change detected")
}
func (c *Refresh) reload() {
if c.environment.config.Reload {
c.environment.reloader.Run()
<-c.environment.reloader.FinishedRunning
}
}
func (c *Refresh) sync() {
if c.environment.config.Sync {
c.environment.sync.Sync()
}
}