mirror of
https://github.com/chatmail/core.git
synced 2026-04-29 11:26:29 +03:00
use AtomicBool for skip_next_idle_wait
This commit is contained in:
20
src/imap.rs
20
src/imap.rs
@@ -45,8 +45,7 @@ pub struct Imap {
|
|||||||
session: Arc<Mutex<Option<Session>>>,
|
session: Arc<Mutex<Option<Session>>>,
|
||||||
connected: Arc<Mutex<bool>>,
|
connected: Arc<Mutex<bool>>,
|
||||||
interrupt: Arc<Mutex<Option<stop_token::StopSource>>>,
|
interrupt: Arc<Mutex<Option<stop_token::StopSource>>>,
|
||||||
skip_next_idle_wait: Arc<Mutex<bool>>,
|
skip_next_idle_wait: AtomicBool,
|
||||||
|
|
||||||
should_reconnect: AtomicBool,
|
should_reconnect: AtomicBool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +119,7 @@ impl Imap {
|
|||||||
config: Arc::new(RwLock::new(ImapConfig::default())),
|
config: Arc::new(RwLock::new(ImapConfig::default())),
|
||||||
interrupt: Arc::new(Mutex::new(None)),
|
interrupt: Arc::new(Mutex::new(None)),
|
||||||
connected: Arc::new(Mutex::new(false)),
|
connected: Arc::new(Mutex::new(false)),
|
||||||
skip_next_idle_wait: Arc::new(Mutex::new(false)),
|
skip_next_idle_wait: AtomicBool::new(false),
|
||||||
should_reconnect: AtomicBool::new(false),
|
should_reconnect: AtomicBool::new(false),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -783,10 +782,10 @@ impl Imap {
|
|||||||
let (idle_wait, interrupt) = handle.wait_with_timeout(timeout);
|
let (idle_wait, interrupt) = handle.wait_with_timeout(timeout);
|
||||||
*self.interrupt.lock().await = Some(interrupt);
|
*self.interrupt.lock().await = Some(interrupt);
|
||||||
|
|
||||||
if *self.skip_next_idle_wait.lock().await {
|
if self.skip_next_idle_wait.load(Ordering::Relaxed) {
|
||||||
// interrupt_idle has happened before we
|
// interrupt_idle has happened before we
|
||||||
// provided self.interrupt
|
// provided self.interrupt
|
||||||
*self.skip_next_idle_wait.lock().await = false;
|
self.skip_next_idle_wait.store(false, Ordering::Relaxed);
|
||||||
std::mem::drop(idle_wait);
|
std::mem::drop(idle_wait);
|
||||||
info!(context, "Idle wait was skipped");
|
info!(context, "Idle wait was skipped");
|
||||||
} else {
|
} else {
|
||||||
@@ -811,10 +810,10 @@ impl Imap {
|
|||||||
let (idle_wait, interrupt) = handle.wait_with_timeout(timeout);
|
let (idle_wait, interrupt) = handle.wait_with_timeout(timeout);
|
||||||
*self.interrupt.lock().await = Some(interrupt);
|
*self.interrupt.lock().await = Some(interrupt);
|
||||||
|
|
||||||
if *self.skip_next_idle_wait.lock().await {
|
if self.skip_next_idle_wait.load(Ordering::Relaxed) {
|
||||||
// interrupt_idle has happened before we
|
// interrupt_idle has happened before we
|
||||||
// provided self.interrupt
|
// provided self.interrupt
|
||||||
*self.skip_next_idle_wait.lock().await = false;
|
self.skip_next_idle_wait.store(false, Ordering::Relaxed);
|
||||||
std::mem::drop(idle_wait);
|
std::mem::drop(idle_wait);
|
||||||
info!(context, "Idle wait was skipped");
|
info!(context, "Idle wait was skipped");
|
||||||
} else {
|
} else {
|
||||||
@@ -891,8 +890,11 @@ impl Imap {
|
|||||||
pub fn interrupt_idle(&self) {
|
pub fn interrupt_idle(&self) {
|
||||||
task::block_on(async move {
|
task::block_on(async move {
|
||||||
if self.interrupt.lock().await.take().is_none() {
|
if self.interrupt.lock().await.take().is_none() {
|
||||||
// idle wait is not running
|
// idle wait is not running, signal it needs to skip
|
||||||
*self.skip_next_idle_wait.lock().await = true;
|
self.skip_next_idle_wait.store(true, Ordering::Relaxed);
|
||||||
|
|
||||||
|
// meanwhile idle-wait may have produced the interrupter
|
||||||
|
let _ = self.interrupt.lock().await.take();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user