MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / try_enqueue

Method try_enqueue

nodedb-bridge/src/wfq.rs:107–120  ·  view source on GitHub ↗

Attempt to enqueue `item` for `database_id`. Returns `Err(item)` if the total queue has reached capacity.

(&mut self, database_id: u64, item: T)

Source from the content-addressed store, hash-verified

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.

Calls 4

entryMethod · 0.80
insertMethod · 0.45
expectMethod · 0.45
get_mutMethod · 0.45