mirror of
https://github.com/chatmail/core.git
synced 2026-04-26 01:46:34 +03:00
update deps
and switch to new channels in async-std@1.8
This commit is contained in:
committed by
Floris Bruynooghe
parent
93bd9422e7
commit
b3fe74e0f0
1009
Cargo.lock
generated
1009
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -299,7 +299,7 @@ async fn start(args: Vec<String>) -> Result<(), Error> {
|
|||||||
.output_stream(OutputStreamType::Stdout)
|
.output_stream(OutputStreamType::Stdout)
|
||||||
.build();
|
.build();
|
||||||
let mut selected_chat = ChatId::default();
|
let mut selected_chat = ChatId::default();
|
||||||
let (reader_s, reader_r) = async_std::sync::channel(100);
|
let (reader_s, reader_r) = async_std::channel::bounded(100);
|
||||||
let input_loop = async_std::task::spawn_blocking(move || {
|
let input_loop = async_std::task::spawn_blocking(move || {
|
||||||
let h = DcHelper {
|
let h = DcHelper {
|
||||||
completer: FilenameCompleter::new(),
|
completer: FilenameCompleter::new(),
|
||||||
@@ -322,7 +322,7 @@ async fn start(args: Vec<String>) -> Result<(), Error> {
|
|||||||
Ok(line) => {
|
Ok(line) => {
|
||||||
// TODO: ignore "set mail_pw"
|
// TODO: ignore "set mail_pw"
|
||||||
rl.add_history_entry(line.as_str());
|
rl.add_history_entry(line.as_str());
|
||||||
async_std::task::block_on(reader_s.send(line));
|
async_std::task::block_on(reader_s.send(line)).unwrap();
|
||||||
}
|
}
|
||||||
Err(ReadlineError::Interrupted) | Err(ReadlineError::Eof) => {
|
Err(ReadlineError::Interrupted) | Err(ReadlineError::Eof) => {
|
||||||
println!("Exiting...");
|
println!("Exiting...");
|
||||||
|
|||||||
@@ -341,7 +341,7 @@ async fn configure(ctx: &Context, param: &mut LoginParam) -> Result<()> {
|
|||||||
progress!(ctx, 600);
|
progress!(ctx, 600);
|
||||||
|
|
||||||
// Configure IMAP
|
// Configure IMAP
|
||||||
let (_s, r) = async_std::sync::channel(1);
|
let (_s, r) = async_std::channel::bounded(1);
|
||||||
let mut imap = Imap::new(r);
|
let mut imap = Imap::new(r);
|
||||||
|
|
||||||
let mut imap_configured = false;
|
let mut imap_configured = false;
|
||||||
|
|||||||
@@ -8,9 +8,12 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::{bail, ensure, Result};
|
use anyhow::{bail, ensure, Result};
|
||||||
use async_std::path::{Path, PathBuf};
|
use async_std::{
|
||||||
use async_std::sync::{channel, Arc, Mutex, Receiver, RwLock, Sender};
|
channel::{bounded as channel, Receiver, Sender},
|
||||||
use async_std::task;
|
path::{Path, PathBuf},
|
||||||
|
sync::{Arc, Mutex, RwLock},
|
||||||
|
task,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::chat::{get_chat_cnt, ChatId};
|
use crate::chat::{get_chat_cnt, ChatId};
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
@@ -249,7 +252,9 @@ impl Context {
|
|||||||
let s_a = &self.running_state;
|
let s_a = &self.running_state;
|
||||||
let mut s = s_a.write().await;
|
let mut s = s_a.write().await;
|
||||||
if let Some(cancel) = s.cancel_sender.take() {
|
if let Some(cancel) = s.cancel_sender.take() {
|
||||||
cancel.send(()).await;
|
if let Err(err) = cancel.send(()).await {
|
||||||
|
warn!(self, "could not cancel ongoing: {:?}", err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.ongoing_running && !s.shall_stop_ongoing {
|
if s.ongoing_running && !s.shall_stop_ongoing {
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
|
use async_std::channel::{bounded as channel, Receiver, Sender, TrySendError};
|
||||||
use async_std::path::PathBuf;
|
use async_std::path::PathBuf;
|
||||||
use async_std::sync::{channel, Receiver, Sender, TrySendError};
|
|
||||||
use strum::EnumProperty;
|
use strum::EnumProperty;
|
||||||
|
|
||||||
use crate::chat::ChatId;
|
use crate::chat::ChatId;
|
||||||
@@ -35,7 +35,7 @@ impl Events {
|
|||||||
// try again
|
// try again
|
||||||
self.emit(event);
|
self.emit(event);
|
||||||
}
|
}
|
||||||
Err(TrySendError::Disconnected(_)) => {
|
Err(TrySendError::Closed(_)) => {
|
||||||
unreachable!("unable to emit event, channel disconnected");
|
unreachable!("unable to emit event, channel disconnected");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ use async_imap::{
|
|||||||
error::Result as ImapResult,
|
error::Result as ImapResult,
|
||||||
types::{Capability, Fetch, Flag, Mailbox, Name, NameAttribute},
|
types::{Capability, Fetch, Flag, Mailbox, Name, NameAttribute},
|
||||||
};
|
};
|
||||||
|
use async_std::channel::Receiver;
|
||||||
use async_std::prelude::*;
|
use async_std::prelude::*;
|
||||||
use async_std::sync::Receiver;
|
|
||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
|
|
||||||
use crate::constants::{
|
use crate::constants::{
|
||||||
|
|||||||
136
src/scheduler.rs
136
src/scheduler.rs
@@ -1,6 +1,8 @@
|
|||||||
use async_std::prelude::*;
|
use async_std::prelude::*;
|
||||||
use async_std::sync::{channel, Receiver, Sender};
|
use async_std::{
|
||||||
use async_std::task;
|
channel::{bounded as channel, Receiver, Sender},
|
||||||
|
task,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::dc_tools::maybe_add_time_based_warnings;
|
use crate::dc_tools::maybe_add_time_based_warnings;
|
||||||
@@ -52,46 +54,45 @@ async fn inbox_loop(ctx: Context, started: Sender<()>, inbox_handlers: ImapConne
|
|||||||
shutdown_sender,
|
shutdown_sender,
|
||||||
} = inbox_handlers;
|
} = inbox_handlers;
|
||||||
|
|
||||||
let fut = {
|
let ctx1 = ctx.clone();
|
||||||
let ctx = ctx.clone();
|
let fut = async move {
|
||||||
async move {
|
started.send(()).await.unwrap();
|
||||||
started.send(()).await;
|
let ctx = ctx1;
|
||||||
|
|
||||||
// track number of continously executed jobs
|
// track number of continously executed jobs
|
||||||
let mut jobs_loaded = 0;
|
let mut jobs_loaded = 0;
|
||||||
let mut info = InterruptInfo::default();
|
let mut info = InterruptInfo::default();
|
||||||
loop {
|
loop {
|
||||||
match job::load_next(&ctx, Thread::Imap, &info).await {
|
match job::load_next(&ctx, Thread::Imap, &info).await {
|
||||||
Some(job) if jobs_loaded <= 20 => {
|
Some(job) if jobs_loaded <= 20 => {
|
||||||
jobs_loaded += 1;
|
jobs_loaded += 1;
|
||||||
job::perform_job(&ctx, job::Connection::Inbox(&mut connection), job).await;
|
job::perform_job(&ctx, job::Connection::Inbox(&mut connection), job).await;
|
||||||
info = Default::default();
|
info = Default::default();
|
||||||
|
}
|
||||||
|
Some(job) => {
|
||||||
|
// Let the fetch run, but return back to the job afterwards.
|
||||||
|
jobs_loaded = 0;
|
||||||
|
if ctx.get_config_bool(Config::InboxWatch).await {
|
||||||
|
info!(ctx, "postponing imap-job {} to run fetch...", job);
|
||||||
|
fetch(&ctx, &mut connection).await;
|
||||||
}
|
}
|
||||||
Some(job) => {
|
}
|
||||||
// Let the fetch run, but return back to the job afterwards.
|
None => {
|
||||||
jobs_loaded = 0;
|
jobs_loaded = 0;
|
||||||
if ctx.get_config_bool(Config::InboxWatch).await {
|
|
||||||
info!(ctx, "postponing imap-job {} to run fetch...", job);
|
// Expunge folder if needed, e.g. if some jobs have
|
||||||
fetch(&ctx, &mut connection).await;
|
// deleted messages on the server.
|
||||||
}
|
if let Err(err) = connection.maybe_close_folder(&ctx).await {
|
||||||
|
warn!(ctx, "failed to close folder: {:?}", err);
|
||||||
}
|
}
|
||||||
None => {
|
|
||||||
jobs_loaded = 0;
|
|
||||||
|
|
||||||
// Expunge folder if needed, e.g. if some jobs have
|
maybe_add_time_based_warnings(&ctx).await;
|
||||||
// deleted messages on the server.
|
|
||||||
if let Err(err) = connection.maybe_close_folder(&ctx).await {
|
|
||||||
warn!(ctx, "failed to close folder: {:?}", err);
|
|
||||||
}
|
|
||||||
|
|
||||||
maybe_add_time_based_warnings(&ctx).await;
|
info = if ctx.get_config_bool(Config::InboxWatch).await {
|
||||||
|
fetch_idle(&ctx, &mut connection, Config::ConfiguredInboxFolder).await
|
||||||
info = if ctx.get_config_bool(Config::InboxWatch).await {
|
} else {
|
||||||
fetch_idle(&ctx, &mut connection, Config::ConfiguredInboxFolder).await
|
connection.fake_idle(&ctx, None).await
|
||||||
} else {
|
};
|
||||||
connection.fake_idle(&ctx, None).await
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,7 +105,7 @@ async fn inbox_loop(ctx: Context, started: Sender<()>, inbox_handlers: ImapConne
|
|||||||
})
|
})
|
||||||
.race(fut)
|
.race(fut)
|
||||||
.await;
|
.await;
|
||||||
shutdown_sender.send(()).await;
|
shutdown_sender.send(()).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn fetch(ctx: &Context, connection: &mut Imap) {
|
async fn fetch(ctx: &Context, connection: &mut Imap) {
|
||||||
@@ -185,14 +186,14 @@ async fn simple_imap_loop(
|
|||||||
shutdown_sender,
|
shutdown_sender,
|
||||||
} = inbox_handlers;
|
} = inbox_handlers;
|
||||||
|
|
||||||
let fut = {
|
let ctx1 = ctx.clone();
|
||||||
let ctx = ctx.clone();
|
|
||||||
async move {
|
|
||||||
started.send(()).await;
|
|
||||||
|
|
||||||
loop {
|
let fut = async move {
|
||||||
fetch_idle(&ctx, &mut connection, folder).await;
|
started.send(()).await.unwrap();
|
||||||
}
|
let ctx = ctx1;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
fetch_idle(&ctx, &mut connection, folder).await;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -203,7 +204,7 @@ async fn simple_imap_loop(
|
|||||||
})
|
})
|
||||||
.race(fut)
|
.race(fut)
|
||||||
.await;
|
.await;
|
||||||
shutdown_sender.send(()).await;
|
shutdown_sender.send(()).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn smtp_loop(ctx: Context, started: Sender<()>, smtp_handlers: SmtpConnectionHandlers) {
|
async fn smtp_loop(ctx: Context, started: Sender<()>, smtp_handlers: SmtpConnectionHandlers) {
|
||||||
@@ -217,25 +218,24 @@ async fn smtp_loop(ctx: Context, started: Sender<()>, smtp_handlers: SmtpConnect
|
|||||||
idle_interrupt_receiver,
|
idle_interrupt_receiver,
|
||||||
} = smtp_handlers;
|
} = smtp_handlers;
|
||||||
|
|
||||||
let fut = {
|
let ctx1 = ctx.clone();
|
||||||
let ctx = ctx.clone();
|
let fut = async move {
|
||||||
async move {
|
started.send(()).await.unwrap();
|
||||||
started.send(()).await;
|
let ctx = ctx1;
|
||||||
|
|
||||||
let mut interrupt_info = Default::default();
|
let mut interrupt_info = Default::default();
|
||||||
loop {
|
loop {
|
||||||
match job::load_next(&ctx, Thread::Smtp, &interrupt_info).await {
|
match job::load_next(&ctx, Thread::Smtp, &interrupt_info).await {
|
||||||
Some(job) => {
|
Some(job) => {
|
||||||
info!(ctx, "executing smtp job");
|
info!(ctx, "executing smtp job");
|
||||||
job::perform_job(&ctx, job::Connection::Smtp(&mut connection), job).await;
|
job::perform_job(&ctx, job::Connection::Smtp(&mut connection), job).await;
|
||||||
interrupt_info = Default::default();
|
interrupt_info = Default::default();
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
// Fake Idle
|
// Fake Idle
|
||||||
info!(ctx, "smtp fake idle - started");
|
info!(ctx, "smtp fake idle - started");
|
||||||
interrupt_info = idle_interrupt_receiver.recv().await.unwrap_or_default();
|
interrupt_info = idle_interrupt_receiver.recv().await.unwrap_or_default();
|
||||||
info!(ctx, "smtp fake idle - interrupted")
|
info!(ctx, "smtp fake idle - interrupted")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -248,7 +248,7 @@ async fn smtp_loop(ctx: Context, started: Sender<()>, smtp_handlers: SmtpConnect
|
|||||||
})
|
})
|
||||||
.race(fut)
|
.race(fut)
|
||||||
.await;
|
.await;
|
||||||
shutdown_sender.send(()).await;
|
shutdown_sender.send(()).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Scheduler {
|
impl Scheduler {
|
||||||
@@ -285,7 +285,7 @@ impl Scheduler {
|
|||||||
.await
|
.await
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
mvbox_start_send.send(()).await;
|
mvbox_start_send.send(()).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.get_config_bool(Config::SentboxWatch).await {
|
if ctx.get_config_bool(Config::SentboxWatch).await {
|
||||||
@@ -300,7 +300,7 @@ impl Scheduler {
|
|||||||
.await
|
.await
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
sentbox_start_send.send(()).await;
|
sentbox_start_send.send(()).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let smtp_handle = {
|
let smtp_handle = {
|
||||||
@@ -448,7 +448,7 @@ impl ConnectionState {
|
|||||||
/// Shutdown this connection completely.
|
/// Shutdown this connection completely.
|
||||||
async fn stop(&self) {
|
async fn stop(&self) {
|
||||||
// Trigger shutdown of the run loop.
|
// Trigger shutdown of the run loop.
|
||||||
self.stop_sender.send(()).await;
|
self.stop_sender.send(()).await.unwrap();
|
||||||
// Wait for a notification that the run loop has been shutdown.
|
// Wait for a notification that the run loop has been shutdown.
|
||||||
self.shutdown_receiver.recv().await.ok();
|
self.shutdown_receiver.recv().await.ok();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user