Struct async_io::Timer [−][src]
A future or stream that emits timed events.
Timers are futures that output a single Instant
when they fire.
Timers are also streams that can output Instant
s periodically.
Examples
Sleep for 1 second:
use async_io::Timer; use std::time::Duration; Timer::after(Duration::from_secs(1)).await;
Timeout after 1 second:
use async_io::Timer; use futures_lite::FutureExt; use std::time::Duration; let addrs = async_net::resolve("google.com:80") .or(async { Timer::after(Duration::from_secs(10)).await; Err(std::io::ErrorKind::TimedOut.into()) }) .await?;
Implementations
impl Timer
[src]
pub fn after(duration: Duration) -> Timerⓘ
[src]
Creates a timer that emits an event once after the given duration of time.
Examples
use async_io::Timer; use std::time::Duration; Timer::after(Duration::from_secs(1)).await;
pub fn at(instant: Instant) -> Timerⓘ
[src]
Creates a timer that emits an event once at the given time instant.
Examples
use async_io::Timer; use std::time::{Duration, Instant}; let now = Instant::now(); let when = now + Duration::from_secs(1); Timer::at(when).await;
pub fn interval(period: Duration) -> Timerⓘ
[src]
Creates a timer that emits events periodically.
Examples
use async_io::Timer; use futures_lite::StreamExt; use std::time::{Duration, Instant}; let period = Duration::from_secs(1); Timer::interval(period).next().await;
pub fn interval_at(start: Instant, period: Duration) -> Timerⓘ
[src]
Creates a timer that emits events periodically, starting at start
.
Examples
use async_io::Timer; use futures_lite::StreamExt; use std::time::{Duration, Instant}; let start = Instant::now(); let period = Duration::from_secs(1); Timer::interval_at(start, period).next().await;
pub fn set_after(&mut self, duration: Duration)
[src]
Sets the timer to emit an en event once after the given duration of time.
Note that resetting a timer is different from creating a new timer because
set_after()
does not remove the waker associated with the task
that is polling the timer.
Examples
use async_io::Timer; use std::time::Duration; let mut t = Timer::after(Duration::from_secs(1)); t.set_after(Duration::from_millis(100));
pub fn set_at(&mut self, instant: Instant)
[src]
Sets the timer to emit an event once at the given time instant.
Note that resetting a timer is different from creating a new timer because
set_at()
does not remove the waker associated with the task
that is polling the timer.
Examples
use async_io::Timer; use std::time::{Duration, Instant}; let mut t = Timer::after(Duration::from_secs(1)); let now = Instant::now(); let when = now + Duration::from_secs(1); t.set_at(when);
pub fn set_interval(&mut self, period: Duration)
[src]
Sets the timer to emit events periodically.
Note that resetting a timer is different from creating a new timer because
set_interval()
does not remove the waker associated with the
task that is polling the timer.
Examples
use async_io::Timer; use futures_lite::StreamExt; use std::time::{Duration, Instant}; let mut t = Timer::after(Duration::from_secs(1)); let period = Duration::from_secs(2); t.set_interval(period);
pub fn set_interval_at(&mut self, start: Instant, period: Duration)
[src]
Sets the timer to emit events periodically, starting at start
.
Note that resetting a timer is different from creating a new timer because
set_interval_at()
does not remove the waker associated with
the task that is polling the timer.
Examples
use async_io::Timer; use futures_lite::StreamExt; use std::time::{Duration, Instant}; let mut t = Timer::after(Duration::from_secs(1)); let start = Instant::now(); let period = Duration::from_secs(2); t.set_interval_at(start, period);
Trait Implementations
impl Debug for Timer
[src]
impl Drop for Timer
[src]
impl Future for Timer
[src]
type Output = Instant
The type of value produced on completion.
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>
[src]
impl Stream for Timer
[src]
Auto Trait Implementations
impl RefUnwindSafe for Timer
impl Send for Timer
impl Sync for Timer
impl Unpin for Timer
impl UnwindSafe for Timer
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<F> FutureExt for F where
F: Future + ?Sized,
[src]
F: Future + ?Sized,
pub fn poll(&mut self, cx: &mut Context<'_>) -> Poll<Self::Output> where
Self: Unpin,
[src]
Self: Unpin,
pub fn or<F>(self, other: F) -> Or<Self, F> where
F: Future<Output = Self::Output>,
[src]
F: Future<Output = Self::Output>,
pub fn race<F>(self, other: F) -> Race<Self, F> where
F: Future<Output = Self::Output>,
[src]
F: Future<Output = Self::Output>,
pub fn catch_unwind(self) -> CatchUnwind<Self> where
Self: UnwindSafe,
[src]
Self: UnwindSafe,
pub fn boxed<'a>(
self
) -> Pin<Box<dyn Future<Output = Self::Output> + 'a + Send, Global>> where
Self: Send + 'a,
[src]
self
) -> Pin<Box<dyn Future<Output = Self::Output> + 'a + Send, Global>> where
Self: Send + 'a,
pub fn boxed_local<'a>(
self
) -> Pin<Box<dyn Future<Output = Self::Output> + 'a, Global>> where
Self: 'a,
[src]
self
) -> Pin<Box<dyn Future<Output = Self::Output> + 'a, Global>> where
Self: 'a,
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<F> IntoFuture for F where
F: Future,
[src]
F: Future,
type Output = <F as Future>::Output
into_future
)The output that the future will produce on completion.
type Future = F
into_future
)Which kind of future are we turning this into?
pub fn into_future(self) -> <F as IntoFuture>::Future
[src]
impl<S> StreamExt for S where
S: Stream + ?Sized,
[src]
S: Stream + ?Sized,
pub fn poll_next(&mut self, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> where
Self: Unpin,
[src]
Self: Unpin,
pub fn next(&mut self) -> NextFuture<'_, Self> where
Self: Unpin,
[src]
Self: Unpin,
pub fn try_next<T, E>(&mut self) -> TryNextFuture<'_, Self> where
Self: Stream<Item = Result<T, E>> + Unpin,
[src]
Self: Stream<Item = Result<T, E>> + Unpin,
pub fn count(self) -> CountFuture<Self>
[src]
pub fn map<T, F>(self, f: F) -> Map<Self, F> where
F: FnMut(Self::Item) -> T,
[src]
F: FnMut(Self::Item) -> T,
pub fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F> where
F: FnMut(Self::Item) -> U,
U: Stream,
[src]
F: FnMut(Self::Item) -> U,
U: Stream,
pub fn flatten(self) -> Flatten<Self> where
Self::Item: Stream,
[src]
Self::Item: Stream,
pub fn then<F, Fut>(self, f: F) -> Then<Self, F, Fut> where
F: FnMut(Self::Item) -> Fut,
Fut: Future,
[src]
F: FnMut(Self::Item) -> Fut,
Fut: Future,
pub fn filter<P>(self, predicate: P) -> Filter<Self, P> where
P: FnMut(&Self::Item) -> bool,
[src]
P: FnMut(&Self::Item) -> bool,
pub fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F> where
F: FnMut(Self::Item) -> Option<T>,
[src]
F: FnMut(Self::Item) -> Option<T>,
pub fn take(self, n: usize) -> Take<Self>
[src]
pub fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P> where
P: FnMut(&Self::Item) -> bool,
[src]
P: FnMut(&Self::Item) -> bool,
pub fn skip(self, n: usize) -> Skip<Self>
[src]
pub fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P> where
P: FnMut(&Self::Item) -> bool,
[src]
P: FnMut(&Self::Item) -> bool,
pub fn step_by(self, step: usize) -> StepBy<Self>
[src]
pub fn chain<U>(self, other: U) -> Chain<Self, U> where
U: Stream<Item = Self::Item>,
[src]
U: Stream<Item = Self::Item>,
pub fn cloned<'a, T>(self) -> Cloned<Self> where
Self: Stream<Item = &'a T>,
T: Clone + 'a,
[src]
Self: Stream<Item = &'a T>,
T: Clone + 'a,
pub fn copied<'a, T>(self) -> Copied<Self> where
Self: Stream<Item = &'a T>,
T: Copy + 'a,
[src]
Self: Stream<Item = &'a T>,
T: Copy + 'a,
pub fn collect<C>(self) -> CollectFuture<Self, C> where
C: Default + Extend<Self::Item>,
[src]
C: Default + Extend<Self::Item>,
pub fn try_collect<T, E, C>(self) -> TryCollectFuture<Self, C> where
Self: Stream<Item = Result<T, E>>,
C: Default + Extend<T>,
[src]
Self: Stream<Item = Result<T, E>>,
C: Default + Extend<T>,
pub fn partition<B, P>(self, predicate: P) -> PartitionFuture<Self, P, B> where
P: FnMut(&Self::Item) -> bool,
B: Default + Extend<Self::Item>,
[src]
P: FnMut(&Self::Item) -> bool,
B: Default + Extend<Self::Item>,
pub fn fold<T, F>(self, init: T, f: F) -> FoldFuture<Self, F, T> where
F: FnMut(T, Self::Item) -> T,
[src]
F: FnMut(T, Self::Item) -> T,
pub fn try_fold<T, E, F, B>(
&mut self,
init: B,
f: F
) -> TryFoldFuture<'_, Self, F, B> where
Self: Stream<Item = Result<T, E>> + Unpin,
F: FnMut(B, T) -> Result<B, E>,
[src]
&mut self,
init: B,
f: F
) -> TryFoldFuture<'_, Self, F, B> where
Self: Stream<Item = Result<T, E>> + Unpin,
F: FnMut(B, T) -> Result<B, E>,
pub fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F> where
F: FnMut(&mut St, Self::Item) -> Option<B>,
[src]
F: FnMut(&mut St, Self::Item) -> Option<B>,
pub fn fuse(self) -> Fuse<Self>
[src]
pub fn cycle(self) -> Cycle<Self> where
Self: Clone,
[src]
Self: Clone,
pub fn enumerate(self) -> Enumerate<Self>
[src]
pub fn inspect<F>(self, f: F) -> Inspect<Self, F> where
F: FnMut(&Self::Item),
[src]
F: FnMut(&Self::Item),
pub fn nth(&mut self, n: usize) -> NthFuture<'_, Self> where
Self: Unpin,
[src]
Self: Unpin,
pub fn last(self) -> LastFuture<Self>
[src]
pub fn find<P>(&mut self, predicate: P) -> FindFuture<'_, Self, P> where
Self: Unpin,
P: FnMut(&Self::Item) -> bool,
[src]
Self: Unpin,
P: FnMut(&Self::Item) -> bool,
pub fn find_map<F, B>(&mut self, f: F) -> FindMapFuture<'_, Self, F> where
Self: Unpin,
F: FnMut(Self::Item) -> Option<B>,
[src]
Self: Unpin,
F: FnMut(Self::Item) -> Option<B>,
pub fn position<P>(&mut self, predicate: P) -> PositionFuture<'_, Self, P> where
Self: Unpin,
P: FnMut(Self::Item) -> bool,
[src]
Self: Unpin,
P: FnMut(Self::Item) -> bool,
pub fn all<P>(&mut self, predicate: P) -> AllFuture<'_, Self, P> where
Self: Unpin,
P: FnMut(Self::Item) -> bool,
[src]
Self: Unpin,
P: FnMut(Self::Item) -> bool,
pub fn any<P>(&mut self, predicate: P) -> AnyFuture<'_, Self, P> where
Self: Unpin,
P: FnMut(Self::Item) -> bool,
[src]
Self: Unpin,
P: FnMut(Self::Item) -> bool,
pub fn for_each<F>(self, f: F) -> ForEachFuture<Self, F> where
F: FnMut(Self::Item),
[src]
F: FnMut(Self::Item),
pub fn try_for_each<F, E>(&mut self, f: F) -> TryForEachFuture<'_, Self, F> where
Self: Unpin,
F: FnMut(Self::Item) -> Result<(), E>,
[src]
Self: Unpin,
F: FnMut(Self::Item) -> Result<(), E>,
pub fn zip<U>(self, other: U) -> Zip<Self, U> where
U: Stream,
[src]
U: Stream,
pub fn unzip<A, B, FromA, FromB>(self) -> UnzipFuture<Self, FromA, FromB> where
Self: Stream<Item = (A, B)>,
FromA: Default + Extend<A>,
FromB: Default + Extend<B>,
[src]
Self: Stream<Item = (A, B)>,
FromA: Default + Extend<A>,
FromB: Default + Extend<B>,
pub fn or<S>(self, other: S) -> Or<Self, S> where
S: Stream<Item = Self::Item>,
[src]
S: Stream<Item = Self::Item>,
pub fn race<S>(self, other: S) -> Race<Self, S> where
S: Stream<Item = Self::Item>,
[src]
S: Stream<Item = Self::Item>,
pub fn boxed<'a>(
self
) -> Pin<Box<dyn Stream<Item = Self::Item> + 'a + Send, Global>> where
Self: Send + 'a,
[src]
self
) -> Pin<Box<dyn Stream<Item = Self::Item> + 'a + Send, Global>> where
Self: Send + 'a,
pub fn boxed_local<'a>(
self
) -> Pin<Box<dyn Stream<Item = Self::Item> + 'a, Global>> where
Self: 'a,
[src]
self
) -> Pin<Box<dyn Stream<Item = Self::Item> + 'a, Global>> where
Self: 'a,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,