Use timer instead of ticker
This commit is contained in:
2 files changed
+8
-6
No files matched your search
@@ -477,9 +477,13 @@ func (app *app) loop() {
|
||||
}
|
||||
|
||||
if ev.Has(fsnotify.Write) || ev.Has(fsnotify.Chmod) {
|
||||
app.nav.watcherWrites[ev.Name] = true
|
||||
if !app.nav.watcherWrites[ev.Name] {
|
||||
app.nav.watcherWrites[ev.Name] = true
|
||||
app.nav.watcherTimer.Stop()
|
||||
app.nav.watcherTimer.Reset(10 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
case <-app.nav.watcherTicker.C:
|
||||
case <-app.nav.watcherTimer.C:
|
||||
for path := range app.nav.watcherWrites {
|
||||
app.updateFile(path, true)
|
||||
currFile, err := app.nav.currFile()
|
||||
|
||||
@@ -468,7 +468,7 @@ type nav struct {
|
||||
watcher *fsnotify.Watcher
|
||||
watcherEvents <-chan fsnotify.Event
|
||||
watcherWrites map[string]bool
|
||||
watcherTicker *time.Ticker
|
||||
watcherTimer *time.Timer
|
||||
}
|
||||
|
||||
func (nav *nav) loadDirInternal(path string) *dir {
|
||||
@@ -607,7 +607,7 @@ func newNav(height int) *nav {
|
||||
jumpList: make([]string, 0),
|
||||
jumpListInd: -1,
|
||||
watcherWrites: make(map[string]bool),
|
||||
watcherTicker: new(time.Ticker),
|
||||
watcherTimer: time.NewTimer(0),
|
||||
}
|
||||
|
||||
return nav
|
||||
@@ -2084,7 +2084,6 @@ func (nav *nav) startWatcher() {
|
||||
|
||||
nav.watcher = watcher
|
||||
nav.watcherEvents = watcher.Events
|
||||
nav.watcherTicker = time.NewTicker(10 * time.Millisecond)
|
||||
}
|
||||
|
||||
func (nav *nav) stopWatcher() {
|
||||
@@ -2096,7 +2095,6 @@ func (nav *nav) stopWatcher() {
|
||||
|
||||
nav.watcher = nil
|
||||
nav.watcherEvents = nil
|
||||
nav.watcherTicker.Stop()
|
||||
}
|
||||
|
||||
func (nav *nav) setWatches() {
|
||||
|
||||
Reference in new issue
Block a user