Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ the env var `GO111MODULE=on`, which enables you to develop outside of
| | | **file watch** |
|`-polling=…` | false | Use polling instead of FS notifications to detect changes. Default is false
|`-polling-interval=…` | 100 | Milliseconds of interval between polling file changes when polling option is selected
|`-work-delay=…` | 900 | Milliseconds to wait (debounce) before starting a build after file changes settle; each new change resets the timer. Must be a positive integer.|
| | | **misc** |
|`-color=_` | false | Colorize the output of the daemon's status messages. |
|`-log-prefix=_` | true | Prefix all child process output with stdout/stderr labels and log timestamps. |
Expand Down
15 changes: 11 additions & 4 deletions daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ There are command line options.
FILE WATCH
-polling - Use polling instead of FS notifications to detect changes. Default is false
-polling-interval - Milliseconds of interval between polling file changes when polling option is selected
-work-delay - Milliseconds to wait (debounce) before starting a build after file changes settle (must be > 0)

MISC
-color - Enable colorized output
Expand Down Expand Up @@ -82,8 +83,9 @@ import (
"github.com/fatih/color"
)

// Milliseconds to wait for the next job to begin after a file change
const WorkDelay = 900
// DefaultWorkDelay is the default -work-delay value: milliseconds to wait before
// starting a build after file changes (inrush / debounce).
const DefaultWorkDelay = 900

// Default pattern to match files which trigger a build
const FilePattern = `(.+\.go|.+\.c)$`
Expand Down Expand Up @@ -135,6 +137,7 @@ var (
flagVerbose = flag.Bool("verbose", false, "Be verbose about which directories are watched.")
flagPolling = flag.Bool("polling", false, "Use polling method to watch file change instead of fsnotify")
flagPollingInterval = flag.Int("polling-interval", 100, "Milliseconds of interval between polling file changes when polling option is selected")
flagWorkDelay = flag.Int("work-delay", DefaultWorkDelay, "Milliseconds to wait (debounce) before starting a build after file changes settle; must be > 0")

// initialized in main() due to custom type.
flagDirectories globList
Expand Down Expand Up @@ -205,11 +208,11 @@ func matchesPattern(pattern *regexp.Regexp, file string) bool {
}

// Accept build jobs and start building when there are no jobs rushing in.
// The inrush protection is WorkDelay milliseconds long, in this period
// The inrush protection is -work-delay milliseconds long; in this period
// every incoming job will reset the timer.
func builder(jobs <-chan string, buildStarted chan<- string, buildDone chan<- bool) {
createThreshold := func() <-chan time.Time {
return time.After(time.Duration(WorkDelay * time.Millisecond))
return time.After(time.Duration(*flagWorkDelay) * time.Millisecond)
}

threshold := createThreshold()
Expand Down Expand Up @@ -409,6 +412,10 @@ func main() {

flag.Parse()

if *flagWorkDelay <= 0 {
log.Fatal("-work-delay must be a positive integer")
}

if !*flagLogPrefix {
log.SetFlags(0)
}
Expand Down