mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-09-28 12:10:37 +00:00
time: move error types into time::error
(#2938)
This commit is contained in:
parent
ec99e61945
commit
0893841f31
@ -7,7 +7,7 @@
|
||||
use crate::time::wheel::{self, Wheel};
|
||||
|
||||
use futures_core::ready;
|
||||
use tokio::time::{sleep_until, Duration, Error, Instant, Sleep};
|
||||
use tokio::time::{error::Error, sleep_until, Duration, Instant, Sleep};
|
||||
|
||||
use slab::Slab;
|
||||
use std::cmp;
|
||||
@ -67,7 +67,7 @@ use std::task::{self, Poll};
|
||||
/// Using `DelayQueue` to manage cache entries.
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// use tokio::time::Error;
|
||||
/// use tokio::time::error::Error;
|
||||
/// use tokio_util::time::{DelayQueue, delay_queue};
|
||||
///
|
||||
/// use futures::ready;
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::stream::{Fuse, Stream};
|
||||
use crate::time::{Elapsed, Instant, Sleep};
|
||||
use crate::time::{error::Elapsed, Instant, Sleep};
|
||||
|
||||
use core::future::Future;
|
||||
use core::pin::Pin;
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::time::driver::Entry;
|
||||
use crate::time::Error;
|
||||
use crate::time::error::Error;
|
||||
|
||||
use std::ptr;
|
||||
use std::sync::atomic::AtomicPtr;
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::loom::sync::atomic::AtomicU64;
|
||||
use crate::sync::AtomicWaker;
|
||||
use crate::time::driver::{Handle, Inner};
|
||||
use crate::time::{Duration, Error, Instant};
|
||||
use crate::time::{error::Error, Duration, Instant};
|
||||
|
||||
use std::cell::UnsafeCell;
|
||||
use std::ptr;
|
||||
|
@ -11,7 +11,7 @@ pub(crate) use self::handle::Handle;
|
||||
|
||||
use crate::loom::sync::atomic::{AtomicU64, AtomicUsize};
|
||||
use crate::park::{Park, Unpark};
|
||||
use crate::time::{wheel, Error};
|
||||
use crate::time::{error::Error, wheel};
|
||||
use crate::time::{Clock, Duration, Instant};
|
||||
|
||||
use std::sync::atomic::Ordering::{Acquire, Relaxed, Release, SeqCst};
|
||||
@ -204,7 +204,7 @@ where
|
||||
|
||||
/// Fires the entry if it needs to, otherwise queue it to be processed later.
|
||||
fn add_entry(&mut self, entry: Arc<Entry>, when: u64) {
|
||||
use crate::time::wheel::InsertError;
|
||||
use crate::time::error::InsertError;
|
||||
|
||||
entry.set_when_internal(Some(when));
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
//! Time error types.
|
||||
|
||||
use self::Kind::*;
|
||||
use std::error;
|
||||
use std::fmt;
|
||||
@ -32,6 +34,18 @@ enum Kind {
|
||||
Invalid = 3,
|
||||
}
|
||||
|
||||
/// Error returned by `Timeout`.
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Elapsed(());
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum InsertError {
|
||||
Elapsed,
|
||||
Invalid,
|
||||
}
|
||||
|
||||
// ===== impl Error =====
|
||||
|
||||
impl Error {
|
||||
/// Creates an error representing a shutdown timer.
|
||||
pub fn shutdown() -> Error {
|
||||
@ -90,3 +104,25 @@ impl fmt::Display for Error {
|
||||
write!(fmt, "{}", descr)
|
||||
}
|
||||
}
|
||||
|
||||
// ===== impl Elapsed =====
|
||||
|
||||
impl Elapsed {
|
||||
pub(crate) fn new() -> Self {
|
||||
Elapsed(())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Elapsed {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
"deadline has elapsed".fmt(fmt)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for Elapsed {}
|
||||
|
||||
impl From<Elapsed> for std::io::Error {
|
||||
fn from(_err: Elapsed) -> std::io::Error {
|
||||
std::io::ErrorKind::TimedOut.into()
|
||||
}
|
||||
}
|
||||
|
@ -98,8 +98,7 @@ pub use sleep::{sleep, sleep_until, Sleep};
|
||||
|
||||
pub(crate) mod driver;
|
||||
|
||||
mod error;
|
||||
pub use error::Error;
|
||||
pub mod error;
|
||||
|
||||
mod instant;
|
||||
pub use self::instant::Instant;
|
||||
@ -109,7 +108,7 @@ pub use interval::{interval, interval_at, Interval};
|
||||
|
||||
mod timeout;
|
||||
#[doc(inline)]
|
||||
pub use timeout::{timeout, timeout_at, Elapsed, Timeout};
|
||||
pub use timeout::{timeout, timeout_at, Timeout};
|
||||
|
||||
mod wheel;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::time::driver::{Entry, Handle};
|
||||
use crate::time::{Duration, Error, Instant};
|
||||
use crate::time::{error::Error, Duration, Instant};
|
||||
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
|
@ -4,10 +4,9 @@
|
||||
//!
|
||||
//! [`Timeout`]: struct@Timeout
|
||||
|
||||
use crate::time::{sleep_until, Duration, Instant, Sleep};
|
||||
use crate::time::{error::Elapsed, sleep_until, Duration, Instant, Sleep};
|
||||
|
||||
use pin_project_lite::pin_project;
|
||||
use std::fmt;
|
||||
use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
use std::task::{self, Poll};
|
||||
@ -112,18 +111,6 @@ pin_project! {
|
||||
}
|
||||
}
|
||||
|
||||
/// Error returned by `Timeout`.
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Elapsed(());
|
||||
|
||||
impl Elapsed {
|
||||
// Used on StreamExt::timeout
|
||||
#[allow(unused)]
|
||||
pub(crate) fn new() -> Self {
|
||||
Elapsed(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Timeout<T> {
|
||||
pub(crate) fn new_with_delay(value: T, delay: Sleep) -> Timeout<T> {
|
||||
Timeout { value, delay }
|
||||
@ -161,24 +148,8 @@ where
|
||||
|
||||
// Now check the timer
|
||||
match me.delay.poll(cx) {
|
||||
Poll::Ready(()) => Poll::Ready(Err(Elapsed(()))),
|
||||
Poll::Ready(()) => Poll::Ready(Err(Elapsed::new())),
|
||||
Poll::Pending => Poll::Pending,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ===== impl Elapsed =====
|
||||
|
||||
impl fmt::Display for Elapsed {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
"deadline has elapsed".fmt(fmt)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for Elapsed {}
|
||||
|
||||
impl From<Elapsed> for std::io::Error {
|
||||
fn from(_err: Elapsed) -> std::io::Error {
|
||||
std::io::ErrorKind::TimedOut.into()
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::time::driver::Entry;
|
||||
use crate::time::{driver::Entry, error::InsertError};
|
||||
|
||||
mod level;
|
||||
pub(crate) use self::level::Expiration;
|
||||
@ -50,12 +50,6 @@ const NUM_LEVELS: usize = 6;
|
||||
/// The maximum duration of a `Sleep`
|
||||
const MAX_DURATION: u64 = (1 << (6 * NUM_LEVELS)) - 1;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum InsertError {
|
||||
Elapsed,
|
||||
Invalid,
|
||||
}
|
||||
|
||||
impl Wheel {
|
||||
/// Create a new timing wheel
|
||||
pub(crate) fn new() -> Wheel {
|
||||
|
Loading…
x
Reference in New Issue
Block a user