Watch For File Changes In A Rust App
This works, but there's a better way to do it where you just look at the paths direclty to see what's changed that way :
2uxj96li
This was an attempt to debounce. I though it was mostly working but that turns out to be less of the case than I originally thought. Leaving this here as a mark of progress, but more work needs to be done for the solution.
It's good enough for what I need for now though
Though... now it looks like the issue I'm seeing is because a child process keeps running? I don't know enough about how this works yet.
Proceed with caution.
- >
This is what I'm doing to watch for file changes to trigger re - renders in my blog engine. It uses the watchexec we crate.
use Error;
use Duration;
use Result;
use PathBuf;
use ;
use FileEventKind;
use ModifyKind;
use Tag;
async
- I'm still new to Rust so don't be surpirsed if there's weird looking stuff up there.
- This is using the [TODO: Code shorthand span ] approach which is more is designed to run external commands, but it works fine for internal usage for me
- I've got other examples to post from my archive that show the more low level approach but I moved to this becuase it was easier to figure out how to setup a semi - debounce
- The ` .action _ throttle() [TODO: Code shorthand span ] uses a ` Duration [TODO: Code shorthand span ] which is a second followed by nanoseconds. The goal with this approach is to throttle event togehter every 100ms to act as a debounce. I'm not confident that it's setup in an optimal way or even that it's doing what I think it is, but it's doing the job I want
- The way the throttle works starts the clock on the first event that comes in from a group. It doesn't keep getting pushed out like it a standard debounce. For my site's content engine that doesn't matter
- It should be possible to set things up directly without the ` .reconfigure() ` . This is built off an example that used that approach so I'm sticking with it for sake of getting something out the door