Merge pull request #293 from nhooyr/improve-watch-ab11
watch.go: Ignore first error in ensureAddWatch
This commit is contained in:
commit
d21e36b407
2 changed files with 12 additions and 5 deletions
|
|
@ -36,5 +36,7 @@
|
||||||
[#159](https://github.com/terrastruct/d2/issues/159)
|
[#159](https://github.com/terrastruct/d2/issues/159)
|
||||||
- Fixes markdown newlines created with a trailing double space or backslash.
|
- Fixes markdown newlines created with a trailing double space or backslash.
|
||||||
[#214](https://github.com/terrastruct/d2/pull/214)
|
[#214](https://github.com/terrastruct/d2/pull/214)
|
||||||
- Fixes images not loading in PNG exports
|
- Fixes images not loading in PNG exports.
|
||||||
[#224](https://github.com/terrastruct/d2/pull/224)
|
[#224](https://github.com/terrastruct/d2/pull/224)
|
||||||
|
- Avoid logging benign file watching errors.
|
||||||
|
[#293](https://github.com/terrastruct/d2/pull/293)
|
||||||
|
|
|
||||||
11
watch.go
11
watch.go
|
|
@ -251,7 +251,7 @@ func (w *watcher) watchLoop(ctx context.Context) error {
|
||||||
// We missed changes.
|
// We missed changes.
|
||||||
lastModified = mt
|
lastModified = mt
|
||||||
}
|
}
|
||||||
// The purpose of eatBurstTimer is to wait at least 32 milliseconds after a sequence of
|
// The purpose of eatBurstTimer is to wait at least 16 milliseconds after a sequence of
|
||||||
// events to ensure that whomever is editing the file is now done.
|
// events to ensure that whomever is editing the file is now done.
|
||||||
//
|
//
|
||||||
// For example, On macOS editing with neovim, every write I see a chmod immediately
|
// For example, On macOS editing with neovim, every write I see a chmod immediately
|
||||||
|
|
@ -261,7 +261,7 @@ func (w *watcher) watchLoop(ctx context.Context) error {
|
||||||
// Another example would be a very large file where one logical edit becomes write
|
// Another example would be a very large file where one logical edit becomes write
|
||||||
// events. We wouldn't want to try to compile an incomplete file and then report a
|
// events. We wouldn't want to try to compile an incomplete file and then report a
|
||||||
// misleading error.
|
// misleading error.
|
||||||
eatBurstTimer.Reset(time.Millisecond * 32)
|
eatBurstTimer.Reset(time.Millisecond * 16)
|
||||||
case <-eatBurstTimer.C:
|
case <-eatBurstTimer.C:
|
||||||
w.ms.Log.Info.Printf("detected change in %v: recompiling...", w.inputPath)
|
w.ms.Log.Info.Printf("detected change in %v: recompiling...", w.inputPath)
|
||||||
w.requestCompile()
|
w.requestCompile()
|
||||||
|
|
@ -284,7 +284,7 @@ func (w *watcher) requestCompile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *watcher) ensureAddWatch(ctx context.Context) (time.Time, error) {
|
func (w *watcher) ensureAddWatch(ctx context.Context) (time.Time, error) {
|
||||||
interval := time.Second
|
interval := time.Millisecond * 16
|
||||||
tc := time.NewTimer(0)
|
tc := time.NewTimer(0)
|
||||||
<-tc.C
|
<-tc.C
|
||||||
for {
|
for {
|
||||||
|
|
@ -292,11 +292,16 @@ func (w *watcher) ensureAddWatch(ctx context.Context) (time.Time, error) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return mt, nil
|
return mt, nil
|
||||||
}
|
}
|
||||||
|
if interval >= time.Second {
|
||||||
w.ms.Log.Error.Printf("failed to watch inputPath %q: %v (retrying in %v)", w.inputPath, err, interval)
|
w.ms.Log.Error.Printf("failed to watch inputPath %q: %v (retrying in %v)", w.inputPath, err, interval)
|
||||||
|
}
|
||||||
|
|
||||||
tc.Reset(interval)
|
tc.Reset(interval)
|
||||||
select {
|
select {
|
||||||
case <-tc.C:
|
case <-tc.C:
|
||||||
|
if interval < time.Second {
|
||||||
|
interval = time.Second
|
||||||
|
}
|
||||||
if interval < time.Second*16 {
|
if interval < time.Second*16 {
|
||||||
interval *= 2
|
interval *= 2
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue