(&self, process_identifier: i64)
| 232 | } |
| 233 | |
| 234 | pub async fn ensure_polled_agent(&self, process_identifier: i64) -> Result<(), String> { |
| 235 | { |
| 236 | let mut inner = self.inner.lock().await; |
| 237 | inner.prune_stale_polled_agents(); |
| 238 | if inner.agents.contains_key(&process_identifier) { |
| 239 | return Ok(()); |
| 240 | } |
| 241 | if inner.agents.len() >= MAX_POLLED_AGENTS { |
| 242 | return Err("Too many pending NativeScript inspector agents.".to_owned()); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | let connection_id = self.allocate_connection_id().await; |
| 247 | let (outgoing, _receiver) = mpsc::channel::<Value>(1); |
| 248 | let outbox = Arc::new(Mutex::new(VecDeque::new())); |
| 249 | outbox.lock().await.push_back(json!({ |
| 250 | "id": POLLED_INFO_REQUEST_ID, |
| 251 | "method": "Inspector.getInfo", |
| 252 | "params": Value::Null, |
| 253 | })); |
| 254 | |
| 255 | let agent = InspectorAgentHandle { |
| 256 | connection_id, |
| 257 | created_at: Instant::now(), |
| 258 | info: Value::Null, |
| 259 | outgoing, |
| 260 | outbox, |
| 261 | outbox_notify: Arc::new(Notify::new()), |
| 262 | pending: Arc::new(Mutex::new(HashMap::new())), |
| 263 | next_request_id: Arc::new(AtomicU64::new(1)), |
| 264 | }; |
| 265 | |
| 266 | self.register(process_identifier, agent).await; |
| 267 | Ok(()) |
| 268 | } |
| 269 | |
| 270 | pub async fn query_with_timeout( |
| 271 | &self, |
no test coverage detected