explicitely drop the search permit

This commit is contained in:
Tamo 2024-08-28 14:29:25 +02:00
parent 42e7499260
commit 92b151607c
5 changed files with 36 additions and 4 deletions

View file

@ -33,11 +33,20 @@ pub struct SearchQueue {
/// You should only run search requests while holding this permit.
/// Once it's dropped, a new search request will be able to process.
/// You should always try to drop the permit yourself calling the `drop` async method on it.
#[derive(Debug)]
pub struct Permit {
sender: mpsc::Sender<()>,
}
impl Permit {
/// Drop the permit giving back on permit to the search queue.
pub async fn drop(self) {
// if the channel is closed then the whole instance is down
let _ = self.sender.send(()).await;
}
}
impl Drop for Permit {
fn drop(&mut self) {
let sender = self.sender.clone();