jobs: save handle for each Job
If we save the JoinHandle for each task, we can cancel it in future commits if we have to timeout network requests.async
parent
08c462801d
commit
ddafde7b37
|
@ -256,12 +256,12 @@ impl Composer {
|
|||
));
|
||||
}
|
||||
Ok(fut) => {
|
||||
let (mut rcvr, job_id) = context.accounts[coordinates.0]
|
||||
let (mut rcvr, handle, job_id) = context.accounts[coordinates.0]
|
||||
.job_executor
|
||||
.spawn_specialized(fut);
|
||||
context.accounts[coordinates.0]
|
||||
.active_jobs
|
||||
.insert(job_id, JobRequest::AsBytes);
|
||||
.insert(job_id, JobRequest::AsBytes(handle));
|
||||
if let Ok(Some(parent_bytes)) = try_recv_timeout!(&mut rcvr) {
|
||||
match parent_bytes {
|
||||
Err(err) => {
|
||||
|
|
|
@ -176,10 +176,10 @@ pub trait MailListingTrait: ListingTrait {
|
|||
));
|
||||
}
|
||||
Ok(fut) => {
|
||||
let (rcvr, job_id) = account.job_executor.spawn_specialized(fut);
|
||||
let (rcvr, handle, job_id) = account.job_executor.spawn_specialized(fut);
|
||||
account
|
||||
.active_jobs
|
||||
.insert(job_id, JobRequest::SetFlags(env_hash, rcvr));
|
||||
.insert(job_id, JobRequest::SetFlags(env_hash, handle, rcvr));
|
||||
}
|
||||
},
|
||||
ListingAction::SetUnseen => match envelope.set_unseen(op) {
|
||||
|
@ -189,10 +189,10 @@ pub trait MailListingTrait: ListingTrait {
|
|||
));
|
||||
}
|
||||
Ok(fut) => {
|
||||
let (rcvr, job_id) = account.job_executor.spawn_specialized(fut);
|
||||
let (rcvr, handle, job_id) = account.job_executor.spawn_specialized(fut);
|
||||
account
|
||||
.active_jobs
|
||||
.insert(job_id, JobRequest::SetFlags(env_hash, rcvr));
|
||||
.insert(job_id, JobRequest::SetFlags(env_hash, handle, rcvr));
|
||||
}
|
||||
},
|
||||
ListingAction::Delete => {
|
||||
|
@ -207,10 +207,11 @@ pub trait MailListingTrait: ListingTrait {
|
|||
return;
|
||||
}
|
||||
Ok(fut) => {
|
||||
let (rcvr, job_id) = account.job_executor.spawn_specialized(fut);
|
||||
let (rcvr, handle, job_id) =
|
||||
account.job_executor.spawn_specialized(fut);
|
||||
account
|
||||
.active_jobs
|
||||
.insert(job_id, JobRequest::DeleteMessage(env_hash, rcvr));
|
||||
.insert(job_id, JobRequest::DeleteMessage(env_hash, handle, rcvr));
|
||||
}
|
||||
}
|
||||
continue;
|
||||
|
@ -230,10 +231,12 @@ pub trait MailListingTrait: ListingTrait {
|
|||
return;
|
||||
}
|
||||
Ok(fut) => {
|
||||
let (rcvr, job_id) = account.job_executor.spawn_specialized(fut);
|
||||
account
|
||||
.active_jobs
|
||||
.insert(job_id, JobRequest::SaveMessage(mailbox_hash, rcvr));
|
||||
let (rcvr, handle, job_id) =
|
||||
account.job_executor.spawn_specialized(fut);
|
||||
account.active_jobs.insert(
|
||||
job_id,
|
||||
JobRequest::SaveMessage(mailbox_hash, handle, rcvr),
|
||||
);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
|
@ -253,10 +256,11 @@ pub trait MailListingTrait: ListingTrait {
|
|||
})?;
|
||||
let account = &mut context.accounts[account_pos];
|
||||
let mailbox_hash = account.mailbox_by_path(mailbox_path)?;
|
||||
let (rcvr, job_id) = account.job_executor.spawn_specialized(bytes_fut);
|
||||
let (rcvr, handle, job_id) =
|
||||
account.job_executor.spawn_specialized(bytes_fut);
|
||||
account
|
||||
.active_jobs
|
||||
.insert(job_id, JobRequest::CopyTo(mailbox_hash, rcvr));
|
||||
.insert(job_id, JobRequest::CopyTo(mailbox_hash, handle, rcvr));
|
||||
Ok(())
|
||||
}) {
|
||||
context.replies.push_back(UIEvent::Notification(
|
||||
|
@ -283,10 +287,12 @@ pub trait MailListingTrait: ListingTrait {
|
|||
return;
|
||||
}
|
||||
Ok(fut) => {
|
||||
let (rcvr, job_id) = account.job_executor.spawn_specialized(fut);
|
||||
account
|
||||
.active_jobs
|
||||
.insert(job_id, JobRequest::SaveMessage(mailbox_hash, rcvr));
|
||||
let (rcvr, handle, job_id) =
|
||||
account.job_executor.spawn_specialized(fut);
|
||||
account.active_jobs.insert(
|
||||
job_id,
|
||||
JobRequest::SaveMessage(mailbox_hash, handle, rcvr),
|
||||
);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
|
@ -306,10 +312,11 @@ pub trait MailListingTrait: ListingTrait {
|
|||
})?;
|
||||
let account = &mut context.accounts[account_pos];
|
||||
let mailbox_hash = account.mailbox_by_path(mailbox_path)?;
|
||||
let (rcvr, job_id) = account.job_executor.spawn_specialized(bytes_fut);
|
||||
let (rcvr, handle, job_id) =
|
||||
account.job_executor.spawn_specialized(bytes_fut);
|
||||
account
|
||||
.active_jobs
|
||||
.insert(job_id, JobRequest::CopyTo(mailbox_hash, rcvr));
|
||||
.insert(job_id, JobRequest::CopyTo(mailbox_hash, handle, rcvr));
|
||||
Ok(())
|
||||
}) {
|
||||
context.replies.push_back(UIEvent::Notification(
|
||||
|
@ -339,10 +346,11 @@ pub trait MailListingTrait: ListingTrait {
|
|||
return;
|
||||
}
|
||||
Ok(fut) => {
|
||||
let (rcvr, job_id) = account.job_executor.spawn_specialized(fut);
|
||||
let (rcvr, handle, job_id) =
|
||||
account.job_executor.spawn_specialized(fut);
|
||||
account
|
||||
.active_jobs
|
||||
.insert(job_id, JobRequest::SetFlags(env_hash, rcvr));
|
||||
.insert(job_id, JobRequest::SetFlags(env_hash, handle, rcvr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -357,10 +365,11 @@ pub trait MailListingTrait: ListingTrait {
|
|||
return;
|
||||
}
|
||||
Ok(fut) => {
|
||||
let (rcvr, job_id) = account.job_executor.spawn_specialized(fut);
|
||||
let (rcvr, handle, job_id) =
|
||||
account.job_executor.spawn_specialized(fut);
|
||||
account
|
||||
.active_jobs
|
||||
.insert(job_id, JobRequest::SetFlags(env_hash, rcvr));
|
||||
.insert(job_id, JobRequest::SetFlags(env_hash, handle, rcvr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1534,12 +1534,12 @@ impl Component for CompactListing {
|
|||
self.cursor_pos.1,
|
||||
) {
|
||||
Ok(job) => {
|
||||
let (chan, job_id) = context.accounts[self.cursor_pos.0]
|
||||
let (chan, handle, job_id) = context.accounts[self.cursor_pos.0]
|
||||
.job_executor
|
||||
.spawn_specialized(job);
|
||||
context.accounts[self.cursor_pos.0]
|
||||
.active_jobs
|
||||
.insert(job_id.clone(), crate::conf::accounts::JobRequest::Search);
|
||||
.insert(job_id, crate::conf::accounts::JobRequest::Search(handle));
|
||||
self.search_job = Some((filter_term.to_string(), chan, job_id));
|
||||
}
|
||||
Err(err) => {
|
||||
|
|
|
@ -1354,12 +1354,12 @@ impl Component for ConversationsListing {
|
|||
self.cursor_pos.1,
|
||||
) {
|
||||
Ok(job) => {
|
||||
let (chan, job_id) = context.accounts[self.cursor_pos.0]
|
||||
let (chan, handle, job_id) = context.accounts[self.cursor_pos.0]
|
||||
.job_executor
|
||||
.spawn_specialized(job);
|
||||
context.accounts[self.cursor_pos.0]
|
||||
.active_jobs
|
||||
.insert(job_id, crate::conf::accounts::JobRequest::Search);
|
||||
.insert(job_id, crate::conf::accounts::JobRequest::Search(handle));
|
||||
self.search_job = Some((filter_term.to_string(), chan, job_id));
|
||||
}
|
||||
Err(err) => {
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
use super::EntryStrings;
|
||||
use super::*;
|
||||
use crate::components::utilities::PageMovement;
|
||||
use crate::jobs::{oneshot, JobId};
|
||||
use crate::jobs::{oneshot, JobId, JoinHandle};
|
||||
use std::cmp;
|
||||
use std::iter::FromIterator;
|
||||
|
||||
|
@ -80,7 +80,7 @@ pub struct PlainListing {
|
|||
_row_updates: SmallVec<[ThreadHash; 8]>,
|
||||
color_cache: ColorCache,
|
||||
|
||||
active_jobs: HashMap<JobId, oneshot::Receiver<Result<()>>>,
|
||||
active_jobs: HashMap<JobId, (JoinHandle, oneshot::Receiver<Result<()>>)>,
|
||||
movement: Option<PageMovement>,
|
||||
id: ComponentId,
|
||||
}
|
||||
|
@ -1031,8 +1031,8 @@ impl PlainListing {
|
|||
)));
|
||||
}
|
||||
Ok(fut) => {
|
||||
let (handle, job_id) = account.job_executor.spawn_specialized(fut);
|
||||
self.active_jobs.insert(job_id, handle);
|
||||
let (rcvr, handle, job_id) = account.job_executor.spawn_specialized(fut);
|
||||
self.active_jobs.insert(job_id, (handle, rcvr));
|
||||
}
|
||||
}
|
||||
self.row_updates.push(env_hash);
|
||||
|
@ -1284,12 +1284,13 @@ impl Component for PlainListing {
|
|||
self.cursor_pos.1,
|
||||
) {
|
||||
Ok(job) => {
|
||||
let (chan, job_id) = context.accounts[self.cursor_pos.0]
|
||||
let (chan, handle, job_id) = context.accounts[self.cursor_pos.0]
|
||||
.job_executor
|
||||
.spawn_specialized(job);
|
||||
context.accounts[self.cursor_pos.0]
|
||||
.active_jobs
|
||||
.insert(job_id.clone(), crate::conf::accounts::JobRequest::Search);
|
||||
context.accounts[self.cursor_pos.0].active_jobs.insert(
|
||||
job_id,
|
||||
crate::conf::accounts::JobRequest::Search(handle),
|
||||
);
|
||||
self.search_job = Some((filter_term.to_string(), chan, job_id));
|
||||
}
|
||||
Err(err) => {
|
||||
|
|
|
@ -193,13 +193,16 @@ impl MailView {
|
|||
.and_then(|mut op| op.as_bytes())
|
||||
{
|
||||
Ok(fut) => {
|
||||
let (mut chan, job_id) = account.job_executor.spawn_specialized(fut);
|
||||
let (mut chan, handle, job_id) =
|
||||
account.job_executor.spawn_specialized(fut);
|
||||
if let Ok(Some(bytes_result)) = try_recv_timeout!(&mut chan) {
|
||||
self.state = MailViewState::Loaded { body: bytes_result };
|
||||
} else {
|
||||
self.state = MailViewState::LoadingBody { job_id, chan };
|
||||
self.active_jobs.insert(job_id);
|
||||
account.active_jobs.insert(job_id, JobRequest::AsBytes);
|
||||
account
|
||||
.active_jobs
|
||||
.insert(job_id, JobRequest::AsBytes(handle));
|
||||
context
|
||||
.replies
|
||||
.push_back(UIEvent::StatusEvent(StatusEvent::NewJob(job_id)));
|
||||
|
@ -218,10 +221,11 @@ impl MailView {
|
|||
.and_then(|mut op| op.set_flag(Flag::SEEN, true))
|
||||
{
|
||||
Ok(fut) => {
|
||||
let (rcvr, job_id) = account.job_executor.spawn_specialized(fut);
|
||||
account
|
||||
.active_jobs
|
||||
.insert(job_id, JobRequest::SetFlags(self.coordinates.2, rcvr));
|
||||
let (rcvr, handle, job_id) = account.job_executor.spawn_specialized(fut);
|
||||
account.active_jobs.insert(
|
||||
job_id,
|
||||
JobRequest::SetFlags(self.coordinates.2, handle, rcvr),
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
context.replies.push_back(UIEvent::StatusEvent(
|
||||
|
|
|
@ -157,53 +157,65 @@ pub struct Account {
|
|||
}
|
||||
|
||||
pub enum JobRequest {
|
||||
Mailboxes(oneshot::Receiver<Result<HashMap<MailboxHash, Mailbox>>>),
|
||||
Mailboxes(
|
||||
JoinHandle,
|
||||
oneshot::Receiver<Result<HashMap<MailboxHash, Mailbox>>>,
|
||||
),
|
||||
Get(
|
||||
MailboxHash,
|
||||
JoinHandle,
|
||||
oneshot::Receiver<(
|
||||
Option<Result<Vec<Envelope>>>,
|
||||
Pin<Box<dyn Stream<Item = Result<Vec<Envelope>>> + Send + 'static>>,
|
||||
)>,
|
||||
),
|
||||
IsOnline(oneshot::Receiver<Result<()>>),
|
||||
Refresh(MailboxHash, oneshot::Receiver<Result<()>>),
|
||||
SetFlags(EnvelopeHash, oneshot::Receiver<Result<()>>),
|
||||
SaveMessage(MailboxHash, oneshot::Receiver<Result<()>>),
|
||||
CopyTo(MailboxHash, oneshot::Receiver<Result<Vec<u8>>>),
|
||||
DeleteMessage(EnvelopeHash, oneshot::Receiver<Result<()>>),
|
||||
CreateMailbox(oneshot::Receiver<Result<(MailboxHash, HashMap<MailboxHash, Mailbox>)>>),
|
||||
DeleteMailbox(oneshot::Receiver<Result<HashMap<MailboxHash, Mailbox>>>),
|
||||
IsOnline(JoinHandle, oneshot::Receiver<Result<()>>),
|
||||
Refresh(MailboxHash, JoinHandle, oneshot::Receiver<Result<()>>),
|
||||
SetFlags(EnvelopeHash, JoinHandle, oneshot::Receiver<Result<()>>),
|
||||
SaveMessage(MailboxHash, JoinHandle, oneshot::Receiver<Result<()>>),
|
||||
SendMessage(JoinHandle, oneshot::Receiver<Result<()>>),
|
||||
CopyTo(MailboxHash, JoinHandle, oneshot::Receiver<Result<Vec<u8>>>),
|
||||
DeleteMessage(EnvelopeHash, JoinHandle, oneshot::Receiver<Result<()>>),
|
||||
CreateMailbox(
|
||||
JoinHandle,
|
||||
oneshot::Receiver<Result<(MailboxHash, HashMap<MailboxHash, Mailbox>)>>,
|
||||
),
|
||||
DeleteMailbox(
|
||||
JoinHandle,
|
||||
oneshot::Receiver<Result<HashMap<MailboxHash, Mailbox>>>,
|
||||
),
|
||||
//RenameMailbox,
|
||||
Search,
|
||||
AsBytes,
|
||||
SetMailboxPermissions(MailboxHash, oneshot::Receiver<Result<()>>),
|
||||
SetMailboxSubscription(MailboxHash, oneshot::Receiver<Result<()>>),
|
||||
Search(JoinHandle),
|
||||
AsBytes(JoinHandle),
|
||||
SetMailboxPermissions(MailboxHash, JoinHandle, oneshot::Receiver<Result<()>>),
|
||||
SetMailboxSubscription(MailboxHash, JoinHandle, oneshot::Receiver<Result<()>>),
|
||||
Watch(JoinHandle),
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for JobRequest {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
match self {
|
||||
JobRequest::Mailboxes(_) => write!(f, "JobRequest::Mailboxes"),
|
||||
JobRequest::Get(hash, _) => write!(f, "JobRequest::Get({})", hash),
|
||||
JobRequest::IsOnline(_) => write!(f, "JobRequest::IsOnline"),
|
||||
JobRequest::Refresh(_, _) => write!(f, "JobRequest::Refresh"),
|
||||
JobRequest::SetFlags(_, _) => write!(f, "JobRequest::SetFlags"),
|
||||
JobRequest::SaveMessage(_, _) => write!(f, "JobRequest::SaveMessage"),
|
||||
JobRequest::CopyTo(_, _) => write!(f, "JobRequest::CopyTo"),
|
||||
JobRequest::DeleteMessage(_, _) => write!(f, "JobRequest::DeleteMessage"),
|
||||
JobRequest::CreateMailbox(_) => write!(f, "JobRequest::CreateMailbox"),
|
||||
JobRequest::DeleteMailbox(_) => write!(f, "JobRequest::DeleteMailbox"),
|
||||
JobRequest::Mailboxes(_, _) => write!(f, "JobRequest::Mailboxes"),
|
||||
JobRequest::Get(hash, _, _) => write!(f, "JobRequest::Get({})", hash),
|
||||
JobRequest::IsOnline(_, _) => write!(f, "JobRequest::IsOnline"),
|
||||
JobRequest::Refresh(_, _, _) => write!(f, "JobRequest::Refresh"),
|
||||
JobRequest::SetFlags(_, _, _) => write!(f, "JobRequest::SetFlags"),
|
||||
JobRequest::SaveMessage(_, _, _) => write!(f, "JobRequest::SaveMessage"),
|
||||
JobRequest::CopyTo(_, _, _) => write!(f, "JobRequest::CopyTo"),
|
||||
JobRequest::DeleteMessage(_, _, _) => write!(f, "JobRequest::DeleteMessage"),
|
||||
JobRequest::CreateMailbox(_, _) => write!(f, "JobRequest::CreateMailbox"),
|
||||
JobRequest::DeleteMailbox(_, _) => write!(f, "JobRequest::DeleteMailbox"),
|
||||
//JobRequest::RenameMailbox,
|
||||
JobRequest::Search => write!(f, "JobRequest::Search"),
|
||||
JobRequest::AsBytes => write!(f, "JobRequest::AsBytes"),
|
||||
JobRequest::SetMailboxPermissions(_, _) => {
|
||||
JobRequest::Search(_) => write!(f, "JobRequest::Search"),
|
||||
JobRequest::AsBytes(_) => write!(f, "JobRequest::AsBytes"),
|
||||
JobRequest::SetMailboxPermissions(_, _, _) => {
|
||||
write!(f, "JobRequest::SetMailboxPermissions")
|
||||
}
|
||||
JobRequest::SetMailboxSubscription(_, _) => {
|
||||
JobRequest::SetMailboxSubscription(_, _, _) => {
|
||||
write!(f, "JobRequest::SetMailboxSubscription")
|
||||
}
|
||||
JobRequest::Watch(_) => write!(f, "JobRequest::Watch"),
|
||||
JobRequest::SendMessage(_, _) => write!(f, "JobRequest::SendMessage"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -218,14 +230,14 @@ impl JobRequest {
|
|||
|
||||
fn is_get(&self, mailbox_hash: MailboxHash) -> bool {
|
||||
match self {
|
||||
JobRequest::Get(h, _) if *h == mailbox_hash => true,
|
||||
JobRequest::Get(h, _, _) if *h == mailbox_hash => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_online(&self) -> bool {
|
||||
match self {
|
||||
JobRequest::IsOnline(_) => true,
|
||||
JobRequest::IsOnline(_, _) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -338,9 +350,9 @@ impl Account {
|
|||
if backend.is_async() {
|
||||
if let Ok(mailboxes_job) = backend.mailboxes_async() {
|
||||
if let Ok(online_job) = backend.is_online_async() {
|
||||
let (rcvr, job_id) =
|
||||
let (rcvr, handle, job_id) =
|
||||
job_executor.spawn_specialized(online_job.then(|_| mailboxes_job));
|
||||
active_jobs.insert(job_id, JobRequest::Mailboxes(rcvr));
|
||||
active_jobs.insert(job_id, JobRequest::Mailboxes(handle, rcvr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -511,13 +523,15 @@ impl Account {
|
|||
if self.is_async {
|
||||
if let Ok(mailbox_job) = self.backend.write().unwrap().get_async(&f) {
|
||||
let mailbox_job = mailbox_job.into_future();
|
||||
let (rcvr, job_id) = self.job_executor.spawn_specialized(mailbox_job);
|
||||
let (rcvr, handle, job_id) =
|
||||
self.job_executor.spawn_specialized(mailbox_job);
|
||||
self.sender
|
||||
.send(ThreadEvent::UIEvent(UIEvent::StatusEvent(
|
||||
StatusEvent::NewJob(job_id),
|
||||
)))
|
||||
.unwrap();
|
||||
self.active_jobs.insert(job_id, JobRequest::Get(*h, rcvr));
|
||||
self.active_jobs
|
||||
.insert(job_id, JobRequest::Get(*h, handle, rcvr));
|
||||
}
|
||||
} else {
|
||||
entry.worker = match Account::new_worker(
|
||||
|
@ -872,14 +886,14 @@ impl Account {
|
|||
}));
|
||||
if self.is_async {
|
||||
if let Ok(refresh_job) = self.backend.write().unwrap().refresh_async(mailbox_hash, r) {
|
||||
let (rcvr, job_id) = self.job_executor.spawn_specialized(refresh_job);
|
||||
let (rcvr, handle, job_id) = self.job_executor.spawn_specialized(refresh_job);
|
||||
self.sender
|
||||
.send(ThreadEvent::UIEvent(UIEvent::StatusEvent(
|
||||
StatusEvent::NewJob(job_id),
|
||||
)))
|
||||
.unwrap();
|
||||
self.active_jobs
|
||||
.insert(job_id, JobRequest::Refresh(mailbox_hash, rcvr));
|
||||
.insert(job_id, JobRequest::Refresh(mailbox_hash, handle, rcvr));
|
||||
}
|
||||
} else {
|
||||
let mut h = self.backend.write().unwrap().refresh(mailbox_hash, r)?;
|
||||
|
@ -994,7 +1008,7 @@ impl Account {
|
|||
) {
|
||||
Ok(mailbox_job) => {
|
||||
let mailbox_job = mailbox_job.into_future();
|
||||
let (rcvr, job_id) =
|
||||
let (rcvr, handle, job_id) =
|
||||
self.job_executor.spawn_specialized(mailbox_job);
|
||||
self.sender
|
||||
.send(ThreadEvent::UIEvent(UIEvent::StatusEvent(
|
||||
|
@ -1003,7 +1017,7 @@ impl Account {
|
|||
.unwrap();
|
||||
self.active_jobs.insert(
|
||||
job_id,
|
||||
JobRequest::Get(mailbox_hash, rcvr),
|
||||
JobRequest::Get(mailbox_hash, handle, rcvr),
|
||||
);
|
||||
}
|
||||
Err(err) => {
|
||||
|
@ -1196,14 +1210,14 @@ impl Account {
|
|||
.write()
|
||||
.unwrap()
|
||||
.save(bytes.to_vec(), mailbox_hash, flags)?;
|
||||
let (rcvr, job_id) = self.job_executor.spawn_specialized(job);
|
||||
let (rcvr, handle, job_id) = self.job_executor.spawn_specialized(job);
|
||||
self.sender
|
||||
.send(ThreadEvent::UIEvent(UIEvent::StatusEvent(
|
||||
StatusEvent::NewJob(job_id),
|
||||
)))
|
||||
.unwrap();
|
||||
self.active_jobs
|
||||
.insert(job_id, JobRequest::SaveMessage(mailbox_hash, rcvr));
|
||||
.insert(job_id, JobRequest::SaveMessage(mailbox_hash, handle, rcvr));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -1419,8 +1433,9 @@ impl Account {
|
|||
}
|
||||
if !self.active_jobs.values().any(JobRequest::is_online) {
|
||||
if let Ok(online_job) = self.backend.read().unwrap().is_online_async() {
|
||||
let (rcvr, job_id) = self.job_executor.spawn_specialized(online_job);
|
||||
self.active_jobs.insert(job_id, JobRequest::IsOnline(rcvr));
|
||||
let (rcvr, handle, job_id) = self.job_executor.spawn_specialized(online_job);
|
||||
self.active_jobs
|
||||
.insert(job_id, JobRequest::IsOnline(handle, rcvr));
|
||||
}
|
||||
}
|
||||
return self.is_online.clone();
|
||||
|
@ -1506,20 +1521,21 @@ impl Account {
|
|||
pub fn process_event(&mut self, job_id: &JobId) -> bool {
|
||||
if self.active_jobs.contains_key(job_id) {
|
||||
match self.active_jobs.remove(job_id).unwrap() {
|
||||
JobRequest::Mailboxes(mut chan) => {
|
||||
JobRequest::Mailboxes(_, mut chan) => {
|
||||
if let Some(mailboxes) = chan.try_recv().unwrap() {
|
||||
if mailboxes.is_err() || self.init(Some(mailboxes.unwrap())).is_err() {
|
||||
if let Ok(mailboxes_job) =
|
||||
self.backend.read().unwrap().mailboxes_async()
|
||||
{
|
||||
let (rcvr, job_id) =
|
||||
let (rcvr, handle, job_id) =
|
||||
self.job_executor.spawn_specialized(mailboxes_job);
|
||||
self.active_jobs.insert(job_id, JobRequest::Mailboxes(rcvr));
|
||||
self.active_jobs
|
||||
.insert(job_id, JobRequest::Mailboxes(handle, rcvr));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
JobRequest::Get(mailbox_hash, mut chan) => {
|
||||
JobRequest::Get(mailbox_hash, _, mut chan) => {
|
||||
self.sender
|
||||
.send(ThreadEvent::UIEvent(UIEvent::StatusEvent(
|
||||
StatusEvent::JobFinished(*job_id),
|
||||
|
@ -1545,14 +1561,15 @@ impl Account {
|
|||
.unwrap();
|
||||
return true;
|
||||
}
|
||||
let (rcvr, job_id) = self.job_executor.spawn_specialized(rest.into_future());
|
||||
let (rcvr, handle, job_id) =
|
||||
self.job_executor.spawn_specialized(rest.into_future());
|
||||
self.sender
|
||||
.send(ThreadEvent::UIEvent(UIEvent::StatusEvent(
|
||||
StatusEvent::NewJob(job_id),
|
||||
)))
|
||||
.unwrap();
|
||||
self.active_jobs
|
||||
.insert(job_id, JobRequest::Get(mailbox_hash, rcvr));
|
||||
.insert(job_id, JobRequest::Get(mailbox_hash, handle, rcvr));
|
||||
let payload = payload.unwrap();
|
||||
if let Err(err) = payload {
|
||||
self.mailbox_entries
|
||||
|
@ -1592,7 +1609,7 @@ impl Account {
|
|||
))))
|
||||
.unwrap();
|
||||
}
|
||||
JobRequest::IsOnline(mut chan) => {
|
||||
JobRequest::IsOnline(_, mut chan) => {
|
||||
let is_online = chan.try_recv().unwrap();
|
||||
if let Some(is_online) = is_online {
|
||||
self.sender
|
||||
|
@ -1610,11 +1627,13 @@ impl Account {
|
|||
self.is_online = is_online;
|
||||
}
|
||||
if let Ok(online_job) = self.backend.read().unwrap().is_online_async() {
|
||||
let (rcvr, job_id) = self.job_executor.spawn_specialized(online_job);
|
||||
self.active_jobs.insert(job_id, JobRequest::IsOnline(rcvr));
|
||||
let (rcvr, handle, job_id) =
|
||||
self.job_executor.spawn_specialized(online_job);
|
||||
self.active_jobs
|
||||
.insert(job_id, JobRequest::IsOnline(handle, rcvr));
|
||||
}
|
||||
}
|
||||
JobRequest::Refresh(_mailbox_hash, mut chan) => {
|
||||
JobRequest::Refresh(_mailbox_hash, _, mut chan) => {
|
||||
let r = chan.try_recv().unwrap();
|
||||
if let Some(r) = r {
|
||||
if r.is_ok() {
|
||||
|
@ -1635,7 +1654,7 @@ impl Account {
|
|||
)))
|
||||
.unwrap();
|
||||
}
|
||||
JobRequest::SetFlags(_, mut chan) => {
|
||||
JobRequest::SetFlags(_, _, mut chan) => {
|
||||
let r = chan.try_recv().unwrap();
|
||||
if let Some(Err(err)) = r {
|
||||
self.sender
|
||||
|
@ -1647,7 +1666,7 @@ impl Account {
|
|||
.expect("Could not send event on main channel");
|
||||
}
|
||||
}
|
||||
JobRequest::SaveMessage(_, mut chan) => {
|
||||
JobRequest::SaveMessage(_, _, mut chan) => {
|
||||
let r = chan.try_recv().unwrap();
|
||||
if let Some(Err(err)) = r {
|
||||
self.sender
|
||||
|
@ -1659,7 +1678,7 @@ impl Account {
|
|||
.expect("Could not send event on main channel");
|
||||
}
|
||||
}
|
||||
JobRequest::CopyTo(mailbox_hash, mut chan) => {
|
||||
JobRequest::CopyTo(mailbox_hash, _, mut chan) => {
|
||||
if let Err(err) = chan
|
||||
.try_recv()
|
||||
.unwrap()
|
||||
|
@ -1675,7 +1694,7 @@ impl Account {
|
|||
.expect("Could not send event on main channel");
|
||||
}
|
||||
}
|
||||
JobRequest::DeleteMessage(_, mut chan) => {
|
||||
JobRequest::DeleteMessage(_, _, mut chan) => {
|
||||
let r = chan.try_recv().unwrap();
|
||||
if let Some(Err(err)) = r {
|
||||
self.sender
|
||||
|
@ -1687,7 +1706,7 @@ impl Account {
|
|||
.expect("Could not send event on main channel");
|
||||
}
|
||||
}
|
||||
JobRequest::CreateMailbox(mut chan) => {
|
||||
JobRequest::CreateMailbox(_, mut chan) => {
|
||||
let r = chan.try_recv().unwrap();
|
||||
if let Some(r) = r {
|
||||
self.sender
|
||||
|
@ -1706,7 +1725,7 @@ impl Account {
|
|||
.expect("Could not send event on main channel");
|
||||
}
|
||||
}
|
||||
JobRequest::DeleteMailbox(mut chan) => {
|
||||
JobRequest::DeleteMailbox(_, mut chan) => {
|
||||
let r = chan.try_recv().unwrap();
|
||||
match r {
|
||||
Some(Err(err)) => {
|
||||
|
@ -1731,14 +1750,14 @@ impl Account {
|
|||
}
|
||||
}
|
||||
//JobRequest::RenameMailbox,
|
||||
JobRequest::Search | JobRequest::AsBytes => {
|
||||
JobRequest::Search(_) | JobRequest::AsBytes(_) => {
|
||||
self.sender
|
||||
.send(ThreadEvent::UIEvent(UIEvent::StatusEvent(
|
||||
StatusEvent::JobFinished(*job_id),
|
||||
)))
|
||||
.unwrap();
|
||||
}
|
||||
JobRequest::SetMailboxPermissions(_, mut chan) => {
|
||||
JobRequest::SetMailboxPermissions(_, _, mut chan) => {
|
||||
let r = chan.try_recv().unwrap();
|
||||
match r {
|
||||
Some(Err(err)) => {
|
||||
|
@ -1768,7 +1787,7 @@ impl Account {
|
|||
None => {}
|
||||
}
|
||||
}
|
||||
JobRequest::SetMailboxSubscription(_, mut chan) => {
|
||||
JobRequest::SetMailboxSubscription(_, _, mut chan) => {
|
||||
let r = chan.try_recv().unwrap();
|
||||
match r {
|
||||
Some(Err(err)) => {
|
||||
|
|
|
@ -183,7 +183,7 @@ impl JobExecutor {
|
|||
}
|
||||
|
||||
///// Spawns a future on the executor.
|
||||
pub fn spawn_specialized<F, R>(&self, future: F) -> (oneshot::Receiver<R>, JobId)
|
||||
pub fn spawn_specialized<F, R>(&self, future: F) -> (oneshot::Receiver<R>, JoinHandle, JobId)
|
||||
where
|
||||
F: Future<Output = R> + Send + 'static,
|
||||
R: Send + 'static,
|
||||
|
@ -195,13 +195,14 @@ impl JobExecutor {
|
|||
let __job_id = job_id;
|
||||
let injector = self.global_queue.clone();
|
||||
// Create a task and schedule it for execution.
|
||||
let (task, _) = async_task::spawn(
|
||||
let (task, handle) = async_task::spawn(
|
||||
async move {
|
||||
let res = future.await;
|
||||
let _ = sender.send(res);
|
||||
finished_sender
|
||||
.send(ThreadEvent::JobFinished(__job_id))
|
||||
.unwrap();
|
||||
Ok(())
|
||||
},
|
||||
move |task| injector.push(MeliTask { task, id: _job_id }),
|
||||
(),
|
||||
|
@ -211,7 +212,7 @@ impl JobExecutor {
|
|||
unparker.unpark();
|
||||
}
|
||||
|
||||
(receiver, job_id)
|
||||
(receiver, JoinHandle(handle), job_id)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue