feat: migrate from async-std to tokio

This commit is contained in:
Friedel Ziegelmayer
2022-06-27 14:05:21 +02:00
committed by GitHub
parent 997fb4061a
commit 290ee20e63
69 changed files with 1781 additions and 2231 deletions

View File

@@ -8,7 +8,7 @@ use anyhow::{Context as _, Result};
use async_imap::Client as ImapClient;
use async_smtp::ServerAddress;
use async_std::net::{self, TcpStream};
use tokio::net::{self, TcpStream};
use super::session::Session;
use crate::login_param::{dc_build_tls, Socks5Config};

View File

@@ -2,7 +2,7 @@ use super::Imap;
use anyhow::{bail, Context as _, Result};
use async_imap::extensions::idle::IdleResponse;
use async_std::prelude::*;
use futures_lite::FutureExt;
use std::time::{Duration, SystemTime};
use crate::{context::Context, scheduler::InterruptInfo};
@@ -87,9 +87,7 @@ impl Imap {
}
}
let session = handle
.done()
.timeout(Duration::from_secs(15))
let session = tokio::time::timeout(Duration::from_secs(15), handle.done())
.await?
.context("IMAP IDLE protocol timed out")?;
self.session = Some(Session { inner: session });
@@ -121,7 +119,7 @@ impl Imap {
// check every minute if there are new messages
// TODO: grow sleep durations / make them more flexible
let mut interval = async_std::stream::interval(Duration::from_secs(60));
let mut interval = tokio::time::interval(Duration::from_secs(60));
enum Event {
Tick,
@@ -131,7 +129,7 @@ impl Imap {
let info = loop {
use futures::future::FutureExt;
match interval
.next()
.tick()
.map(|_| Event::Tick)
.race(
self.idle_interrupt

View File

@@ -1,14 +1,13 @@
use std::{collections::BTreeMap, time::Instant};
use anyhow::{Context as _, Result};
use futures::stream::StreamExt;
use crate::config::Config;
use crate::imap::Imap;
use crate::log::LogExt;
use crate::{context::Context, imap::FolderMeaning};
use async_std::stream::StreamExt;
use super::{get_folder_meaning, get_folder_meaning_by_name};
impl Imap {
@@ -104,7 +103,7 @@ impl Imap {
let list = session
.list(Some(""), Some("*"))
.await?
.filter_map(|f| f.ok_or_log_msg(context, "list_folders() can't get folder"));
.filter_map(|f| async { f.ok_or_log_msg(context, "list_folders() can't get folder") });
Ok(list.collect().await)
}
}

View File

@@ -2,8 +2,8 @@ use std::ops::{Deref, DerefMut};
use async_imap::Session as ImapSession;
use async_native_tls::TlsStream;
use async_std::net::TcpStream;
use fast_socks5::client::Socks5Stream;
use tokio::net::TcpStream;
#[derive(Debug)]
pub(crate) struct Session {
@@ -11,7 +11,7 @@ pub(crate) struct Session {
}
pub(crate) trait SessionStream:
async_std::io::Read + async_std::io::Write + Unpin + Send + Sync + std::fmt::Debug
tokio::io::AsyncRead + tokio::io::AsyncWrite + Unpin + Send + Sync + std::fmt::Debug
{
}