Struct async_io::Timer [−][src]
pub struct Timer { /* fields omitted */ }
Expand description
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]
impl Timer
[src]pub fn after(duration: Duration) -> 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]
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]
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]
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]
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]
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]
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]
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
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> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<F> FutureExt for F where
F: Future + ?Sized,
[src]
impl<F> FutureExt for F where
F: Future + ?Sized,
[src]fn poll(&mut self, cx: &mut Context<'_>) -> Poll<Self::Output> where
Self: Unpin,
[src]
fn poll(&mut self, cx: &mut Context<'_>) -> Poll<Self::Output> where
Self: Unpin,
[src]A convenience for calling Future::poll()
on !
Unpin
types.
fn or<F>(self, other: F) -> Or<Self, F> where
F: Future<Output = Self::Output>,
[src]
fn or<F>(self, other: F) -> Or<Self, F> where
F: Future<Output = Self::Output>,
[src]Returns the result of self
or other
future, preferring self
if both are ready. Read more
fn race<F>(self, other: F) -> Race<Self, F> where
F: Future<Output = Self::Output>,
[src]
fn race<F>(self, other: F) -> Race<Self, F> where
F: Future<Output = Self::Output>,
[src]Returns the result of self
or other
future, with no preference if both are ready. Read more
fn catch_unwind(self) -> CatchUnwind<Self> where
Self: UnwindSafe,
[src]
fn catch_unwind(self) -> CatchUnwind<Self> where
Self: UnwindSafe,
[src]Catches panics while polling the future. Read more
impl<F> IntoFuture for F where
F: Future,
[src]
impl<F> IntoFuture for F where
F: Future,
[src]type Output = <F as Future>::Output
type Output = <F as Future>::Output
into_future
)The output that the future will produce on completion.
type Future = F
type Future = F
into_future
)Which kind of future are we turning this into?
pub fn into_future(self) -> <F as IntoFuture>::Future
[src]
pub fn into_future(self) -> <F as IntoFuture>::Future
[src]into_future
)Creates a future from a value.
impl<S> StreamExt for S where
S: Stream + ?Sized,
[src]
impl<S> StreamExt for S where
S: Stream + ?Sized,
[src]fn poll_next(&mut self, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> where
Self: Unpin,
[src]
fn poll_next(&mut self, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> where
Self: Unpin,
[src]A convenience for calling [Stream::poll_next()
] on !
Unpin
types.
fn next(&mut self) -> NextFuture<'_, Self> where
Self: Unpin,
[src]
fn next(&mut self) -> NextFuture<'_, Self> where
Self: Unpin,
[src]Retrieves the next item in the stream. Read more
fn try_next<T, E>(&mut self) -> TryNextFuture<'_, Self> where
Self: Stream<Item = Result<T, E>> + Unpin,
[src]
fn try_next<T, E>(&mut self) -> TryNextFuture<'_, Self> where
Self: Stream<Item = Result<T, E>> + Unpin,
[src]Retrieves the next item in the stream. Read more
fn count(self) -> CountFuture<Self>
[src]
fn count(self) -> CountFuture<Self>
[src]Counts the number of items in the stream. Read more
fn map<T, F>(self, f: F) -> Map<Self, F> where
F: FnMut(Self::Item) -> T,
[src]
fn map<T, F>(self, f: F) -> Map<Self, F> where
F: FnMut(Self::Item) -> T,
[src]Maps items of the stream to new values using a closure. Read more
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F> where
F: FnMut(Self::Item) -> U,
U: Stream,
[src]
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F> where
F: FnMut(Self::Item) -> U,
U: Stream,
[src]Maps items to streams and then concatenates them. Read more
fn flatten(self) -> Flatten<Self> where
Self::Item: Stream,
[src]
fn flatten(self) -> Flatten<Self> where
Self::Item: Stream,
[src]Concatenates inner streams. Read more
fn then<F, Fut>(self, f: F) -> Then<Self, F, Fut> where
F: FnMut(Self::Item) -> Fut,
Fut: Future,
[src]
fn then<F, Fut>(self, f: F) -> Then<Self, F, Fut> where
F: FnMut(Self::Item) -> Fut,
Fut: Future,
[src]Maps items of the stream to new values using an async closure. Read more
fn filter<P>(self, predicate: P) -> Filter<Self, P> where
P: FnMut(&Self::Item) -> bool,
[src]
fn filter<P>(self, predicate: P) -> Filter<Self, P> where
P: FnMut(&Self::Item) -> bool,
[src]Keeps items of the stream for which predicate
returns true
. Read more
fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F> where
F: FnMut(Self::Item) -> Option<T>,
[src]
fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F> where
F: FnMut(Self::Item) -> Option<T>,
[src]Filters and maps items of the stream using a closure. Read more
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P> where
P: FnMut(&Self::Item) -> bool,
[src]
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P> where
P: FnMut(&Self::Item) -> bool,
[src]Takes items while predicate
returns true
. Read more
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P> where
P: FnMut(&Self::Item) -> bool,
[src]
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P> where
P: FnMut(&Self::Item) -> bool,
[src]Skips items while predicate
returns true
. Read more
fn chain<U>(self, other: U) -> Chain<Self, U> where
U: Stream<Item = Self::Item>,
[src]
fn chain<U>(self, other: U) -> Chain<Self, U> where
U: Stream<Item = Self::Item>,
[src]Appends another stream to the end of this one. Read more
fn cloned<'a, T>(self) -> Cloned<Self> where
Self: Stream<Item = &'a T>,
T: Clone + 'a,
[src]
fn cloned<'a, T>(self) -> Cloned<Self> where
Self: Stream<Item = &'a T>,
T: Clone + 'a,
[src]Clones all items. Read more
fn copied<'a, T>(self) -> Copied<Self> where
Self: Stream<Item = &'a T>,
T: Copy + 'a,
[src]
fn copied<'a, T>(self) -> Copied<Self> where
Self: Stream<Item = &'a T>,
T: Copy + 'a,
[src]Copies all items. Read more
fn collect<C>(self) -> CollectFuture<Self, C> where
C: Default + Extend<Self::Item>,
[src]
fn collect<C>(self) -> CollectFuture<Self, C> where
C: Default + Extend<Self::Item>,
[src]Collects all items in the stream into a collection. Read more
fn try_collect<T, E, C>(self) -> TryCollectFuture<Self, C> where
Self: Stream<Item = Result<T, E>>,
C: Default + Extend<T>,
[src]
fn try_collect<T, E, C>(self) -> TryCollectFuture<Self, C> where
Self: Stream<Item = Result<T, E>>,
C: Default + Extend<T>,
[src]Collects all items in the fallible stream into a collection. Read more
fn partition<B, P>(self, predicate: P) -> PartitionFuture<Self, P, B> where
P: FnMut(&Self::Item) -> bool,
B: Default + Extend<Self::Item>,
[src]
fn partition<B, P>(self, predicate: P) -> PartitionFuture<Self, P, B> where
P: FnMut(&Self::Item) -> bool,
B: Default + Extend<Self::Item>,
[src]Partitions items into those for which predicate
is true
and those for which it is
false
, and then collects them into two collections. Read more
fn fold<T, F>(self, init: T, f: F) -> FoldFuture<Self, F, T> where
F: FnMut(T, Self::Item) -> T,
[src]
fn fold<T, F>(self, init: T, f: F) -> FoldFuture<Self, F, T> where
F: FnMut(T, Self::Item) -> T,
[src]Accumulates a computation over the stream. Read more
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]
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]Accumulates a fallible computation over the stream. Read more
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]
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]Maps items of the stream to new values using a state value and a closure. Read more
fn cycle(self) -> Cycle<Self> where
Self: Clone,
[src]
fn cycle(self) -> Cycle<Self> where
Self: Clone,
[src]Repeats the stream from beginning to end, forever. Read more
fn enumerate(self) -> Enumerate<Self>
[src]
fn enumerate(self) -> Enumerate<Self>
[src]Enumerates items, mapping them to (index, item)
. Read more
fn inspect<F>(self, f: F) -> Inspect<Self, F> where
F: FnMut(&Self::Item),
[src]
fn inspect<F>(self, f: F) -> Inspect<Self, F> where
F: FnMut(&Self::Item),
[src]Calls a closure on each item and passes it on. Read more
fn nth(&mut self, n: usize) -> NthFuture<'_, Self> where
Self: Unpin,
[src]
fn nth(&mut self, n: usize) -> NthFuture<'_, Self> where
Self: Unpin,
[src]Gets the n
th item of the stream. Read more
fn last(self) -> LastFuture<Self>
[src]
fn last(self) -> LastFuture<Self>
[src]Returns the last item in the stream. Read more
fn find<P>(&mut self, predicate: P) -> FindFuture<'_, Self, P> where
Self: Unpin,
P: FnMut(&Self::Item) -> bool,
[src]
fn find<P>(&mut self, predicate: P) -> FindFuture<'_, Self, P> where
Self: Unpin,
P: FnMut(&Self::Item) -> bool,
[src]Finds the first item of the stream for which predicate
returns true
. Read more
fn find_map<F, B>(&mut self, f: F) -> FindMapFuture<'_, Self, F> where
Self: Unpin,
F: FnMut(Self::Item) -> Option<B>,
[src]
fn find_map<F, B>(&mut self, f: F) -> FindMapFuture<'_, Self, F> where
Self: Unpin,
F: FnMut(Self::Item) -> Option<B>,
[src]fn position<P>(&mut self, predicate: P) -> PositionFuture<'_, Self, P> where
Self: Unpin,
P: FnMut(Self::Item) -> bool,
[src]
fn position<P>(&mut self, predicate: P) -> PositionFuture<'_, Self, P> where
Self: Unpin,
P: FnMut(Self::Item) -> bool,
[src]Finds the index of the first item of the stream for which predicate
returns true
. Read more
fn all<P>(&mut self, predicate: P) -> AllFuture<'_, Self, P> where
Self: Unpin,
P: FnMut(Self::Item) -> bool,
[src]
fn all<P>(&mut self, predicate: P) -> AllFuture<'_, Self, P> where
Self: Unpin,
P: FnMut(Self::Item) -> bool,
[src]Tests if predicate
returns true
for all items in the stream. Read more
fn any<P>(&mut self, predicate: P) -> AnyFuture<'_, Self, P> where
Self: Unpin,
P: FnMut(Self::Item) -> bool,
[src]
fn any<P>(&mut self, predicate: P) -> AnyFuture<'_, Self, P> where
Self: Unpin,
P: FnMut(Self::Item) -> bool,
[src]Tests if predicate
returns true
for any item in the stream. Read more
fn for_each<F>(self, f: F) -> ForEachFuture<Self, F> where
F: FnMut(Self::Item),
[src]
fn for_each<F>(self, f: F) -> ForEachFuture<Self, F> where
F: FnMut(Self::Item),
[src]Calls a closure on each item of the stream. Read more
fn try_for_each<F, E>(&mut self, f: F) -> TryForEachFuture<'_, Self, F> where
Self: Unpin,
F: FnMut(Self::Item) -> Result<(), E>,
[src]
fn try_for_each<F, E>(&mut self, f: F) -> TryForEachFuture<'_, Self, F> where
Self: Unpin,
F: FnMut(Self::Item) -> Result<(), E>,
[src]Calls a fallible closure on each item of the stream, stopping on first error. Read more
fn zip<U>(self, other: U) -> Zip<Self, U> where
U: Stream,
[src]
fn zip<U>(self, other: U) -> Zip<Self, U> where
U: Stream,
[src]Zips up two streams into a single stream of pairs. Read more
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]
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]Collects a stream of pairs into a pair of collections. Read more
fn or<S>(self, other: S) -> Or<Self, S> where
S: Stream<Item = Self::Item>,
[src]
fn or<S>(self, other: S) -> Or<Self, S> where
S: Stream<Item = Self::Item>,
[src]Merges with other
stream, preferring items from self
whenever both streams are ready. Read more
fn race<S>(self, other: S) -> Race<Self, S> where
S: Stream<Item = Self::Item>,
[src]
fn race<S>(self, other: S) -> Race<Self, S> where
S: Stream<Item = Self::Item>,
[src]Merges with other
stream, with no preference for either stream when both are ready. Read more