Closed Timmmm closed 2 years ago
Never mind I think I figured it out. Something like this (not tested yet but it compiles which is like 90% as good in Rust!)
impl Backend {
pub fn new(client: Client) -> Self {
// async_watcher() from the notify async example.
let (mut watcher, mut rx) = async_watcher().unwrap();
watcher.watch(Path::new("/path/to/file"), RecursiveMode::NonRecursive).unwrap();
let client_copy = client.clone();
tokio::spawn(async move {
while let Some(res) = rx.next().await {
match res {
Ok(event) => {
println!("changed: {:?}", event);
client_copy.send_custom_request::<ExecuteCommand>(ExecuteCommandParams{
command: "startDebugging".to_string(),
arguments: todo!(),
work_done_progress_params: WorkDoneProgressParams { work_done_token: None },
}).await;
}
Err(e) => println!("watch error: {:?}", e),
}
}
});
Self {
client,
...
}
}
Hi, I'm a bit of a Tokio newbie (I know nothing about it whatsoever), and I was wondering how to send custom requests to the client proactively, in other words not in response to a request from the client. In my case I want to send an
ExecuteCommand
when some file changes.I'm not really sure where to start though - can you give me any hints? I've added a method to my
Backend
like this:And I'm going to use the
Notify
crate which has an async example, but how do I connect them?