Attempt to enqueue `item` for `database_id`. Returns `Err(item)` if the total queue has reached capacity.
(&mut self, database_id: u64, item: T)
| 105 | /// Attempt to enqueue `item` for `database_id`. Returns `Err(item)` if the |
| 106 | /// total queue has reached capacity. |
| 107 | pub fn try_enqueue(&mut self, database_id: u64, item: T) -> Result<(), T> { |
| 108 | if self.total >= self.capacity { |
| 109 | return Err(item); |
| 110 | } |
| 111 | if let std::collections::hash_map::Entry::Vacant(e) = self.queues.entry(database_id) { |
| 112 | e.insert(VirtualQueue::new()); |
| 113 | self.db_order.push_back(database_id); |
| 114 | } |
| 115 | // Safe: we just ensured the key exists. |
| 116 | let vq = self.queues.get_mut(&database_id).expect("just inserted"); |
| 117 | vq.items.push_back(item); |
| 118 | self.total += 1; |
| 119 | Ok(()) |
| 120 | } |
| 121 | |
| 122 | /// Set (or update) the priority class for a database. Applied on the next |
| 123 | /// `pop_next` call after this update. |