mirror of
https://github.com/chatmail/core.git
synced 2026-04-27 02:16:29 +03:00
Fix tokio panic
This might not be needed after all because of https://github.com/tokio-rs/tokio/pull/5710, but since I already wrote the code, I created a PR anyway.
This commit is contained in:
16
src/tools.rs
16
src/tools.rs
@@ -4,6 +4,7 @@
|
||||
#![allow(missing_docs)]
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::cmp::min;
|
||||
use std::fmt;
|
||||
use std::io::{Cursor, Write};
|
||||
use std::mem;
|
||||
@@ -14,7 +15,7 @@ use std::time::{Duration, SystemTime};
|
||||
use anyhow::{bail, Context as _, Result};
|
||||
use base64::Engine as _;
|
||||
use chrono::{Local, NaiveDateTime, NaiveTime, TimeZone};
|
||||
use futures::{StreamExt, TryStreamExt};
|
||||
use futures::{Future, StreamExt, TryStreamExt};
|
||||
use mailparse::dateparse;
|
||||
use mailparse::headers::Headers;
|
||||
use mailparse::MailHeaderMap;
|
||||
@@ -710,6 +711,19 @@ pub(crate) fn strip_rtlo_characters(input_str: &str) -> String {
|
||||
input_str.replace(|char| RTLO_CHARACTERS.contains(&char), "")
|
||||
}
|
||||
|
||||
const THIRTY_YEARS: Duration = Duration::from_secs(60 * 60 * 24 * 365 * 10);
|
||||
|
||||
pub fn sleep(duration: Duration) -> tokio::time::Sleep {
|
||||
tokio::time::sleep(min(THIRTY_YEARS, duration))
|
||||
}
|
||||
|
||||
pub fn timeout<F>(duration: Duration, future: F) -> tokio::time::Timeout<F>
|
||||
where
|
||||
F: Future,
|
||||
{
|
||||
tokio::time::timeout(min(THIRTY_YEARS, duration), future)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#![allow(clippy::indexing_slicing)]
|
||||
|
||||
Reference in New Issue
Block a user