Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #166 #167

Merged
merged 1 commit into from
Dec 14, 2023
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
4 changes: 2 additions & 2 deletions cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ func init() {
var terminateStartup bool
var mode string

devCMD.PersistentFlags().IntVar(&timeoutDuration, "timeout", 2000, "specifies the timeout duration in milliseconds until a change will be detected")
devCMD.PersistentFlags().IntVar(&timeoutDuration, "timeout", 500, "specifies the timeout duration in milliseconds until a change will be detected")
viper.BindPFlag("timeout", devCMD.PersistentFlags().Lookup("timeout"))

devCMD.PersistentFlags().IntVar(&samefileTimeout, "samefiletimeout", 2000, "specifies the timeout duration in milliseconds until a change will be detected for repeating files")
devCMD.PersistentFlags().IntVar(&samefileTimeout, "samefiletimeout", 500, "specifies the timeout duration in milliseconds until a change will be detected for repeating files")
viper.BindPFlag("samefiletimeout", devCMD.PersistentFlags().Lookup("samefiletimeout"))

devCMD.PersistentFlags().IntVar(&port, "hotreloadport", 3005, "port used for hotreload")
Expand Down
16 changes: 14 additions & 2 deletions internal/dev_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,15 @@ func isBlacklistedDirectory(dir string) bool {
return false
}

type DevServerEvent struct {
fsnotify.Event
Processed bool
}

// FileWatcherBundler watches for events given the file watcher and processes change requests as found
func (s *DevServer) FileWatcherBundler(timeout time.Duration, watcher *fsnotify.Watcher) {
var recentEvent *DevServerEvent

for {
time.Sleep(timeout)

Expand All @@ -68,8 +75,13 @@ func (s *DevServer) FileWatcherBundler(timeout time.Duration, watcher *fsnotify.
if isBlacklistedDirectory(e.Name) {
continue
}

err := s.session.DoFileChangeRequest(e.Name, s.fileChangeOpts)
recentEvent = &DevServerEvent{Event: e, Processed: false}
default:
if recentEvent == nil || recentEvent.Processed {
continue
}
recentEvent.Processed = true
err := s.session.DoFileChangeRequest(recentEvent.Name, s.fileChangeOpts)

switch err {
case nil, ErrFileTooRecentlyProcessed:
Expand Down
Loading