mail/view: try cancel env fetch on Drop

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
pull/473/head
Manos Pitsidianakis 2 months ago
parent 60833ee51d
commit 28f45805d7
No known key found for this signature in database
GPG Key ID: 7729C7707F7E09D0

@ -130,7 +130,7 @@ impl MailView {
{
Ok(fut) => {
let mut handle = account.main_loop_handler.job_executor.spawn(
"fetch-envelopes".into(),
"fetch-envelope".into(),
fut,
account.is_async(),
);
@ -154,6 +154,7 @@ impl MailView {
}
} else {
self.state = MailViewState::LoadingBody {
main_loop_handler: self.main_loop_handler.clone(),
handle,
pending_action: pending_action.take(),
};
@ -437,10 +438,9 @@ impl Component for MailView {
if self.active_jobs.contains(job_id) =>
{
match self.state {
MailViewState::LoadingBody {
ref mut handle,
pending_action: _,
} if handle.job_id == *job_id => {
MailViewState::LoadingBody { ref mut handle, .. }
if handle.job_id == *job_id =>
{
match handle.chan.try_recv() {
Err(_) => { /* Job was canceled */ }
Ok(None) => { /* something happened, perhaps a worker

@ -22,7 +22,9 @@
use melib::{text::Truncate, Envelope, Error, Mail, Result};
use super::{EnvelopeView, MailView, ViewSettings};
use crate::{jobs::JoinHandle, mailbox_settings, Component, Context, ShortcutMaps, UIEvent};
use crate::{
jobs::JoinHandle, mailbox_settings, Component, Context, ShortcutMaps, ThreadEvent, UIEvent,
};
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum PendingReplyAction {
@ -39,6 +41,7 @@ pub enum MailViewState {
pending_action: Option<PendingReplyAction>,
},
LoadingBody {
main_loop_handler: crate::MainLoopHandler,
handle: JoinHandle<Result<Vec<u8>>>,
pending_action: Option<PendingReplyAction>,
},
@ -53,6 +56,23 @@ pub enum MailViewState {
},
}
impl Drop for MailViewState {
fn drop(&mut self) {
let Self::LoadingBody {
handle,
main_loop_handler,
..
} = self
else {
return;
};
let Some(ev) = handle.cancel() else {
return;
};
main_loop_handler.send(ThreadEvent::UIEvent(UIEvent::StatusEvent(ev)));
}
}
impl std::fmt::Display for MailViewState {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {

Loading…
Cancel
Save