Files
Sander van Harmelen 6e01a68c91 Prevent double delays and add some docs (#411)
* Fix a few linter warnings

* Prevent double delays and add some docs

I just noticed that reusing `delay` for the poll interval will cause an unintended double delay (first the delay is used as interval, and when a change happened delay is used to wait before building after the change).

Adding a dedicated `poll_interval` parameter allows people to prevent that and apply a more fine-grained configuration.

Also added the new params to the example toml file with some docs which I forgot to do in the initial PR.
2023-04-13 22:01:31 +08:00

25 lines
497 B
Go

package runner
import (
"time"
"github.com/gohugoio/hugo/watcher/filenotify"
)
func newWatcher(cfg *Config) (filenotify.FileWatcher, error) {
if !cfg.Build.Poll {
return filenotify.NewEventWatcher()
}
// Get the poll interval from the config.
interval := cfg.Build.PollInterval
// Make sure the interval is at least 500ms.
if interval < 500 {
interval = 500
}
pollInterval := time.Duration(interval) * time.Millisecond
return filenotify.NewPollingWatcher(pollInterval), nil
}