bokwoon95/wgo

500ms debouncing

the-goodies opened this issue · 1 comments

There's this comment:

// Timer is used to debounce events. Each event does not directly trigger a
// reload, it only resets the timer. Only when the timer is allowed to
// fully expire will the reload actually occur. Debounce delay is currently
// hardcoded to 500ms, will change it only if somebody complains.

I will complain, since this make's it 500ms slower than using air.
In my particular use case, upon changing code, I see refreshed website in ~1.5s using air, while using wgo it takes ~2.0s. Not that of a big difference, but it's clearly noticeable when you want to see visual changes as fast as possible.
Maybe it's possible to add additional flag for this?

Yeah I was waiting for this comment, I've added a -debounce flag which takes in a duration like 10ms (or 0s, if you want it to be instantaneous).

wgo run -debounce 10ms main.go
wgo -debounce 0s go build -o out main.go :: ./out

Additionally, since the debounce delay is now configurable I've lowered the default duration to 300ms which should hopefully be a better balance between user experience and saving hardware resources.