-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathdrop.rs
37 lines (33 loc) · 978 Bytes
/
drop.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use super::*;
use crate::*;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
/// Drop a given set of roots to be dropped (i.e. unregistered)
#[derive(Debug, Serialize, Deserialize, TypeDef)]
pub struct DropRequest {
pub id: u32,
pub roots: Vec<PathBuf>,
}
#[async_trait]
impl RequestHandler<()> for DropRequest {
async fn handle(self) -> Result<()> {
let DropRequest { roots, id } = self;
let mut runtimes = runtimes().await;
let mut drop_runtimes = vec![];
for root in roots.into_iter() {
if !runtimes.contains_key(&root) {
continue;
}
let runtime = runtimes.get_mut(&root).unwrap();
runtime.disconnect(id.clone());
if runtime.is_closed() {
drop_runtimes.push(root)
}
}
for root in drop_runtimes {
runtimes.remove(&root);
}
Ok(())
}
}