Watch filesystem events on `queue.yaml` instead of polling every 3 secs
Currently, when queue.yaml is empty, the scheduling loop just sleeps for three seconds and re-checks if there's any new commands. This is less responsive and it's basically polling.
Crates like notify does filesystem watching, but it's not async. Especially, since its watcher takes std::sync::mpsc::{Sender, Receiver} in its constructor and those are !Sync.
It seems like notify 5.0.0-pre.13 finally fixed this and allow users to provide a callback instead of a std::sync::mpsc::Sender.
Maybe we can wait until notify 5.0.0 is out.
Notes for future reference:
- We edit
queue.yamlourselves, so we need to remove events generated by ourselves. - From the docs:
If you use a delay of more than 30 seconds, you can avoid receiving repetitions of previous events on macOS.. So basically thedelaywe specify seems to be a trade-off between duplicate events and responsiveness. And there is not much advantage in usingnotifyif we are to specify a delay larger than three seconds. Will have to look into this.
Notify 5.0.0 is out. https://github.com/notify-rs/notify/blob/main/examples/async_monitor.rs