(&self, udid: &str, client_id: &str, foreground: bool)
| 266 | |
| 267 | impl StreamClientForegroundRegistry { |
| 268 | pub fn record(&self, udid: &str, client_id: &str, foreground: bool) -> (bool, bool) { |
| 269 | let now = Instant::now(); |
| 270 | let mut clients = self |
| 271 | .inner |
| 272 | .lock() |
| 273 | .unwrap_or_else(|poisoned| poisoned.into_inner()); |
| 274 | clients.retain(|_, state| { |
| 275 | now.duration_since(state.updated_at) <= STREAM_CLIENT_FOREGROUND_TTL |
| 276 | }); |
| 277 | let previous = any_foreground_client_for_udid(&clients, udid); |
| 278 | clients.insert( |
| 279 | (udid.to_owned(), client_id.to_owned()), |
| 280 | StreamClientForegroundState { |
| 281 | foreground, |
| 282 | updated_at: now, |
| 283 | }, |
| 284 | ); |
| 285 | let next = any_foreground_client_for_udid(&clients, udid).unwrap_or(true); |
| 286 | (next, previous != Some(next)) |
| 287 | } |
| 288 | |
| 289 | pub fn remove(&self, udid: &str, client_id: &str) -> (bool, bool) { |
| 290 | let now = Instant::now(); |
no test coverage detected