Frame-based eviction. Called once per frame from `eval()`.
(&mut self)
| 39 | |
| 40 | /// Frame-based eviction. Called once per frame from `eval()`. |
| 41 | pub fn clean(&mut self) { |
| 42 | self.http_requests.retain(|_, entry| { |
| 43 | // Try to receive if still pending |
| 44 | if let HttpRequestState::Pending(pending) = &mut entry.state { |
| 45 | if let Some(result) = pending.try_recv() { |
| 46 | match result { |
| 47 | Ok(resp) => { |
| 48 | entry.state = |
| 49 | HttpRequestState::Done(std::sync::Arc::new(resp)); |
| 50 | } |
| 51 | Err(e) => { |
| 52 | entry.state = HttpRequestState::Error(e); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | match &entry.state { |
| 59 | HttpRequestState::Pending(_) => true, // never evict |
| 60 | _ => { |
| 61 | entry.frames_not_accessed += 1; |
| 62 | entry.frames_not_accessed <= self.max_frames_not_used |
| 63 | } |
| 64 | } |
| 65 | }); |
| 66 | |
| 67 | self.websockets.retain(|_, entry| { |
| 68 | entry.frames_not_accessed += 1; |
| 69 | let disconnected = entry.state.is_disconnected(); |
| 70 | !(disconnected && entry.frames_not_accessed > self.max_frames_not_used) |
| 71 | }); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | fn hash_id(id: &str) -> u64 { |
no test coverage detected