Code Monkey home page Code Monkey logo

Comments (6)

stefanohrmann avatar stefanohrmann commented on September 27, 2024 1

@a-h You are right about the dedup and debounce stuff. I didn't want to change the terminology of fsnotify and I marked the wrong place for the fix. I will correct it.

from templ.

joerdav avatar joerdav commented on September 27, 2024

Thanks @stefanohrmann for the thorough bug report, and your time spent investigating. I've marked this as NeedsInvestigation because I think it could be worth looking into the viability of a fix which doesn't involve removing any commands. Such as ignoring events where the file is empty.

from templ.

stefanohrmann avatar stefanohrmann commented on September 27, 2024

@joerdav You are right and I think it is totally possible to fix this issue in the current implementation if you apply the dedup stuff from fsnotify here:

func (w *RecursiveWatcher) loop() {
for {
select {
case <-w.ctx.Done():
return
case event, ok := <-w.w.Events:
if !ok {
return
}
if event.Has(fsnotify.Create) {
if err := w.Add(event.Name); err != nil {
w.Errors <- err
}
}
// Only notify on templ related files.
if !shouldIncludeFile(event.Name) {
continue
}
w.Events <- event
case err, ok := <-w.w.Errors:
if !ok {
return
}
w.Errors <- err
}
}
}

And with my suggestion i didn't want to remove any subcommands. I wanted to add a dedicated one for watching. But it is ok if this doesn't fit in your structure.

Edit note: Changed the link to right place for the fix.

from templ.

joerdav avatar joerdav commented on September 27, 2024

Ah, not to dismiss your idea, just wanted to explore all options first, and I think minimal change to the outside API would be preferable.

from templ.

a-h avatar a-h commented on September 27, 2024

Great find, and nice write up.

From reading the fsnotify dedup function, it looks like it's more of a debounce than a deduplication, because it doesn't look at the message content (e.g. by having a windowing function or ring buffer of previous messages). It just waits for a timer to elapse before allowing the processing.

I think the logic to handle either a true deduplication (i.e. within a window of 100ms, if there is more than one operation of the same time, discard the earlier ones, and emit the latest), or debounce would go here:

func (w *RecursiveWatcher) loop() {
for {
select {
case <-w.ctx.Done():
return
case event, ok := <-w.w.Events:
if !ok {
return
}
if event.Has(fsnotify.Create) {
if err := w.Add(event.Name); err != nil {
w.Errors <- err
}
}
// Only notify on templ related files.
if !shouldIncludeFile(event.Name) {
continue
}
w.Events <- event
case err, ok := <-w.w.Errors:
if !ok {
return
}
w.Errors <- err
}
}
}

from templ.

joerdav avatar joerdav commented on September 27, 2024

I've created a debounce implementation, for now I've put the window at 100ms I'm hoping that this will be enough.

from templ.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.