pub async fn worker(
working: Receiver<WorkingData>,
errors: Sender<RuntimeError>,
events: Sender<Event, Priority>
) -> Result<(), CriticalError>
Expand description
Launch the filesystem event worker.
While you can run several, you should only have one.
This only does a bare minimum of setup; to actually start the work, you need to set a non-empty
pathset on the WorkingData
with the watch
channel, and send a notification. Take care
not to drop the watch sender: this will cause the worker to stop gracefully, which may not be
what was expected.
Note that the paths emitted by the watcher are normalised. No guarantee is made about the implementation or output of that normalisation (it may change without notice).
Examples
Direct usage:
use async_priority_channel as priority;
use tokio::sync::{mpsc, watch};
use watchexec::fs::{worker, WorkingData};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let (ev_s, _) = priority::bounded(1024);
let (er_s, _) = mpsc::channel(64);
let (wd_s, wd_r) = watch::channel(WorkingData::default());
let mut wkd = WorkingData::default();
wkd.pathset = vec![".".into()];
wd_s.send(wkd)?;
worker(wd_r, er_s, ev_s).await?;
Ok(())
}