id stringlengths 22 133 | text stringlengths 40 40.2k | arch stringclasses 1
value | syntax stringclasses 1
value | kind stringclasses 4
values | repo stringclasses 27
values | path stringlengths 5 116 | license stringclasses 6
values | commit stringlengths 40 40 | source_host stringclasses 1
value | category stringclasses 16
values | source_url stringlengths 85 196 | line_start int64 1 4.28k | line_end int64 4 4.31k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tokio-rs/tokio:tokio/src/time/clock.rs:8 | /// Temporarily stop auto-advancing the clock (see `tokio::time::pause`).
pub(crate) fn inhibit_auto_advance(&self) {
let mut inner = self.inner.lock();
inner.auto_advance_inhibit_count += 1;
}
pub(crate) fn allow_auto_advance(&self) {
let mut inner = self.in... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 013f323def73f85185e2633f1b5f8939cc841318 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/013f323def73f85185e2633f1b5f8939cc841318/tokio/src/time/clock.rs | 281 | 320 |
tokio-rs/tokio:tokio/src/time/clock.rs:5 | inner.unfrozen = Some(std::time::Instant::now());
Ok(())
});
}
/// Advances time.
///
/// Increments the saved `Instant::now()` value by `duration`. Subsequent
/// calls to `Instant::now()` will return the result of the increment.
///
/// This function will make the curr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 0715e6defc4ed358f47654dadaffb3643401ffd8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0715e6defc4ed358f47654dadaffb3643401ffd8/tokio/src/time/clock.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/time/clock.rs:6 | Some(clock) => clock,
None => return Err("time cannot be frozen from outside the Tokio runtime"),
};
clock.advance(duration)
});
crate::task::yield_now().await;
}
/// Returns the current instant, factoring in frozen time.
pub(crate) fn now() -> Inst... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 0715e6defc4ed358f47654dadaffb3643401ffd8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0715e6defc4ed358f47654dadaffb3643401ffd8/tokio/src/time/clock.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/time/clock.rs:7 | if start_paused {
if let Err(msg) = clock.pause() {
panic!("{}", msg);
}
}
clock
}
pub(crate) fn pause(&self) -> Result<(), &'static str> {
let mut inner = self.inner.lock();
if !inner.enable_pausing {... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 0715e6defc4ed358f47654dadaffb3643401ffd8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0715e6defc4ed358f47654dadaffb3643401ffd8/tokio/src/time/clock.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/time/clock.rs:8 | pub(crate) fn can_auto_advance(&self) -> bool {
let inner = self.inner.lock();
inner.unfrozen.is_none() && inner.auto_advance_inhibit_count == 0
}
pub(crate) fn advance(&self, duration: Duration) -> Result<(), &'static str> {
let mut inner = self.inner.lock();
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 0715e6defc4ed358f47654dadaffb3643401ffd8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0715e6defc4ed358f47654dadaffb3643401ffd8/tokio/src/time/clock.rs | 281 | 310 |
tokio-rs/tokio:tokio/src/time/clock.rs:6 | Some(clock) => clock,
None => return Err("time cannot be frozen from outside the Tokio runtime"),
};
clock.advance(duration)
});
crate::task::yield_now().await;
}
/// Returns the current instant, factoring in frozen time.
pub(crate) fn now() -> Inst... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/time/clock.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/time/clock.rs:7 | if start_paused {
if let Err(msg) = clock.pause() {
panic!("{}", msg);
}
}
clock
}
pub(crate) fn pause(&self) -> Result<(), &'static str> {
let mut inner = self.inner.lock();
if !inner.enable_pausing {... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/time/clock.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/time/clock.rs:8 | }
pub(crate) fn can_auto_advance(&self) -> bool {
let inner = self.inner.lock();
inner.unfrozen.is_none() && inner.auto_advance_inhibit_count == 0
}
pub(crate) fn advance(&self, duration: Duration) -> Result<(), &'static str> {
let mut inner = self.inner.loc... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 6871084629ad95c37c7136d865890ab2e371ea12 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6871084629ad95c37c7136d865890ab2e371ea12/tokio/src/time/clock.rs | 281 | 311 |
tokio-rs/tokio:tokio/src/time/clock.rs:3 | /// True if the ability to pause time is enabled.
enable_pausing: bool,
/// Instant to use as the clock's base instant.
base: std::time::Instant,
/// Instant at which the clock was last unfrozen.
unfrozen: Option<std::time::Instant>,
/// Number of `inhibit_auto_advance... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | ee1c940709ad88f83daea29612a924524e37d173 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ee1c940709ad88f83daea29612a924524e37d173/tokio/src/time/clock.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/clock.rs:4 | ///
/// If time is paused and the runtime has no work to do, the clock is
/// auto-advanced to the next pending timer. This means that [`Sleep`] or
/// other timer-backed primitives can cause the runtime to advance the
/// current time when awaited.
///
/// [`Sleep`]: crate::time::Sleep
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | ee1c940709ad88f83daea29612a924524e37d173 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ee1c940709ad88f83daea29612a924524e37d173/tokio/src/time/clock.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/clock.rs:5 | inner.unfrozen = Some(std::time::Instant::now());
Ok(())
})
}
/// Advances time.
///
/// Increments the saved `Instant::now()` value by `duration`. Subsequent
/// calls to `Instant::now()` will return the result of the increment.
///
/// This function will make the curre... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | ee1c940709ad88f83daea29612a924524e37d173 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ee1c940709ad88f83daea29612a924524e37d173/tokio/src/time/clock.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/time/clock.rs:1 | #![cfg_attr(not(feature = "rt"), allow(dead_code))]
//! Source of time abstraction.
//!
//! By default, `std::time::Instant::now()` is used. However, when the
//! `test-util` feature flag is enabled, the values returned for `now()` are
//! configurable.
cfg_not_test_util! {
use crate::time::{Instant};
#[deri... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | abf5d28f2ccaf55ea264f1bea7a1ac1bac6fe98b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/abf5d28f2ccaf55ea264f1bea7a1ac1bac6fe98b/tokio/src/time/clock.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/clock.rs:2 | Err(ref e) if e.is_missing_context() => f(None),
Err(_) => panic!("{}", crate::util::error::THREAD_LOCAL_DESTROYED_ERROR),
};
match res {
Ok(ret) => ret,
Err(msg) => panic!("{}", msg),
}
}
}
cfg_not_rt! {
#[tra... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | abf5d28f2ccaf55ea264f1bea7a1ac1bac6fe98b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/abf5d28f2ccaf55ea264f1bea7a1ac1bac6fe98b/tokio/src/time/clock.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/clock.rs:3 | }
/// Pauses time.
///
/// The current value of `Instant::now()` is saved and all subsequent calls
/// to `Instant::now()` will return the saved value. The saved value can be
/// changed by [`advance`] or by the time auto-advancing once the runtime
/// has no work to do. This only affects the `... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | abf5d28f2ccaf55ea264f1bea7a1ac1bac6fe98b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/abf5d28f2ccaf55ea264f1bea7a1ac1bac6fe98b/tokio/src/time/clock.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/clock.rs:4 | match maybe_clock {
Some(clock) => clock.pause(),
None => Err("time cannot be frozen from outside the Tokio runtime"),
}
})
}
/// Resumes time.
///
/// Clears the saved `Instant::now()` value. Subsequent calls to
/// `Instant::now()` will return t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | abf5d28f2ccaf55ea264f1bea7a1ac1bac6fe98b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/abf5d28f2ccaf55ea264f1bea7a1ac1bac6fe98b/tokio/src/time/clock.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/clock.rs:5 | /// This function will make the current time jump forward by the given
/// duration in one jump. This means that all `sleep` calls with a deadline
/// before the new time will immediately complete "at the same time", and
/// the runtime is free to poll them in any order. Additionally, this
/// method w... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | abf5d28f2ccaf55ea264f1bea7a1ac1bac6fe98b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/abf5d28f2ccaf55ea264f1bea7a1ac1bac6fe98b/tokio/src/time/clock.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/time/clock.rs:6 | pub(crate) fn now() -> Instant {
with_clock(|maybe_clock| {
Ok(if let Some(clock) = maybe_clock {
clock.now()
} else {
Instant::from_std(std::time::Instant::now())
})
})
}
impl Clock {
/// Returns a new `Clock` instance... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | abf5d28f2ccaf55ea264f1bea7a1ac1bac6fe98b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/abf5d28f2ccaf55ea264f1bea7a1ac1bac6fe98b/tokio/src/time/clock.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/time/clock.rs:7 | This is the default Runtime used by `#[tokio::test].");
}
let elapsed = match inner.unfrozen.as_ref() {
Some(v) => v.elapsed(),
None => return Err("time is already frozen")
};
inner.base += elapsed;
inner.unfrozen = None;
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | abf5d28f2ccaf55ea264f1bea7a1ac1bac6fe98b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/abf5d28f2ccaf55ea264f1bea7a1ac1bac6fe98b/tokio/src/time/clock.rs | 241 | 293 |
tokio-rs/tokio:tokio/src/time/clock.rs:8 | pub(crate) fn now(&self) -> Instant {
let inner = self.inner.lock();
let mut ret = inner.base;
if let Some(unfrozen) = inner.unfrozen {
ret += unfrozen.elapsed();
}
Instant::from_std(ret)
}
}
} | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | abf5d28f2ccaf55ea264f1bea7a1ac1bac6fe98b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/abf5d28f2ccaf55ea264f1bea7a1ac1bac6fe98b/tokio/src/time/clock.rs | 281 | 293 |
tokio-rs/tokio:tokio/src/time/clock.rs:1 | #![cfg_attr(not(feature = "rt"), allow(dead_code))]
//! Source of time abstraction.
//!
//! By default, `std::time::Instant::now()` is used. However, when the
//! `test-util` feature flag is enabled, the values returned for `now()` are
//! configurable.
cfg_not_test_util! {
use crate::time::{Instant};
#[deri... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | e14ca72e68fbfa04f12408ed916bf5f857dfa232 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e14ca72e68fbfa04f12408ed916bf5f857dfa232/tokio/src/time/clock.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/clock.rs:2 | Err(_) => panic!("{}", crate::util::error::THREAD_LOCAL_DESTROYED_ERROR),
}
}
}
cfg_not_rt! {
fn clock() -> Option<Clock> {
None
}
}
/// A handle to a source of time.
#[derive(Debug, Clone)]
pub(crate) struct Clock {
inner: Arc<Mutex<Inne... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | e14ca72e68fbfa04f12408ed916bf5f857dfa232 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e14ca72e68fbfa04f12408ed916bf5f857dfa232/tokio/src/time/clock.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/clock.rs:3 | /// Pausing time requires the `current_thread` Tokio runtime. This is the
/// default runtime used by `#[tokio::test]`. The runtime can be initialized
/// with time in a paused state using the `Builder::start_paused` method.
///
/// For cases where time is immediately paused, it is better to pause
/... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | e14ca72e68fbfa04f12408ed916bf5f857dfa232 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e14ca72e68fbfa04f12408ed916bf5f857dfa232/tokio/src/time/clock.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/clock.rs:4 | /// Panics if time is not frozen or if called from outside of the Tokio
/// runtime.
#[track_caller]
pub fn resume() {
let clock = clock().expect("time cannot be frozen from outside the Tokio runtime");
let mut inner = clock.inner.lock();
if inner.unfrozen.is_some() {
pa... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | e14ca72e68fbfa04f12408ed916bf5f857dfa232 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e14ca72e68fbfa04f12408ed916bf5f857dfa232/tokio/src/time/clock.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/clock.rs:5 | /// If the time is paused and there is no work to do, the runtime advances
/// time to the next timer. See [`pause`](pause#auto-advance) for more
/// details.
///
/// [`sleep`]: fn@crate::time::sleep
pub async fn advance(duration: Duration) {
let clock = clock().expect("time cannot be frozen... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | e14ca72e68fbfa04f12408ed916bf5f857dfa232 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e14ca72e68fbfa04f12408ed916bf5f857dfa232/tokio/src/time/clock.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/time/clock.rs:6 | clock
}
#[track_caller]
pub(crate) fn pause(&self) {
let mut inner = self.inner.lock();
if !inner.enable_pausing {
drop(inner); // avoid poisoning the lock
panic!("`time::pause()` requires the `current_thread` Tokio runtime. \
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | e14ca72e68fbfa04f12408ed916bf5f857dfa232 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e14ca72e68fbfa04f12408ed916bf5f857dfa232/tokio/src/time/clock.rs | 201 | 258 |
tokio-rs/tokio:tokio/src/time/clock.rs:7 | }
inner.base += duration;
}
pub(crate) fn now(&self) -> Instant {
let inner = self.inner.lock();
let mut ret = inner.base;
if let Some(unfrozen) = inner.unfrozen {
ret += unfrozen.elapsed();
}
Instant::from_std(... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | e14ca72e68fbfa04f12408ed916bf5f857dfa232 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/e14ca72e68fbfa04f12408ed916bf5f857dfa232/tokio/src/time/clock.rs | 241 | 258 |
tokio-rs/tokio:tokio/src/time/clock.rs:2 | Err(_) => panic!("{}", crate::util::error::THREAD_LOCAL_DESTROYED_ERROR),
}
}
}
cfg_not_rt! {
fn clock() -> Option<Clock> {
None
}
}
/// A handle to a source of time.
#[derive(Debug, Clone)]
pub(crate) struct Clock {
inner: Arc<Mutex<Inne... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 7483509746e1d82d7fc3642fd8431116c96aa387 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7483509746e1d82d7fc3642fd8431116c96aa387/tokio/src/time/clock.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/clock.rs:3 | ///
/// For cases where time is immediately paused, it is better to pause
/// the time using the `main` or `test` macro:
/// ```
/// #[tokio::main(flavor = "current_thread", start_paused = true)]
/// async fn main() {
/// println!("Hello world");
/// }
/// ```
///
/// # Panics... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 7483509746e1d82d7fc3642fd8431116c96aa387 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7483509746e1d82d7fc3642fd8431116c96aa387/tokio/src/time/clock.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/clock.rs:4 | pub fn resume() {
let clock = clock().expect("time cannot be frozen from outside the Tokio runtime");
let mut inner = clock.inner.lock();
if inner.unfrozen.is_some() {
panic!("time is not frozen");
}
inner.unfrozen = Some(std::time::Instant::now());
}
/// A... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 7483509746e1d82d7fc3642fd8431116c96aa387 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7483509746e1d82d7fc3642fd8431116c96aa387/tokio/src/time/clock.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/clock.rs:5 | ///
/// [`sleep`]: fn@crate::time::sleep
pub async fn advance(duration: Duration) {
let clock = clock().expect("time cannot be frozen from outside the Tokio runtime");
clock.advance(duration);
crate::task::yield_now().await;
}
/// Returns the current instant, factoring in froze... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 7483509746e1d82d7fc3642fd8431116c96aa387 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7483509746e1d82d7fc3642fd8431116c96aa387/tokio/src/time/clock.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/time/clock.rs:6 | pub(crate) fn pause(&self) {
let mut inner = self.inner.lock();
if !inner.enable_pausing {
drop(inner); // avoid poisoning the lock
panic!("`time::pause()` requires the `current_thread` Tokio runtime. \
This is the default Runtime used by ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 7483509746e1d82d7fc3642fd8431116c96aa387 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/7483509746e1d82d7fc3642fd8431116c96aa387/tokio/src/time/clock.rs | 201 | 243 |
tokio-rs/tokio:tokio/src/time/clock.rs:1 | #![cfg_attr(not(feature = "rt"), allow(dead_code))]
//! Source of time abstraction.
//!
//! By default, `std::time::Instant::now()` is used. However, when the
//! `test-util` feature flag is enabled, the values returned for `now()` are
//! configurable.
cfg_not_test_util! {
use crate::time::{Instant};
#[deri... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 5c2e27565944178b1bc3f7b3dd2cbce41a663aab | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5c2e27565944178b1bc3f7b3dd2cbce41a663aab/tokio/src/time/clock.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/clock.rs:1 | #![cfg_attr(not(feature = "rt"), allow(dead_code))]
//! Source of time abstraction.
//!
//! By default, `std::time::Instant::now()` is used. However, when the
//! `test-util` feature flag is enabled, the values returned for `now()` are
//! configurable.
cfg_not_test_util! {
use crate::time::{Instant};
#[deri... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 3cc616877d7f0122b4547f4ccd6a6c13b61b2036 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3cc616877d7f0122b4547f4ccd6a6c13b61b2036/tokio/src/time/clock.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/clock.rs:2 | fn clock() -> Option<Clock> {
None
}
}
/// A handle to a source of time.
#[derive(Debug, Clone)]
pub(crate) struct Clock {
inner: Arc<Mutex<Inner>>,
}
#[derive(Debug)]
struct Inner {
/// True if the ability to pause time is enabled.
enable_pausin... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 3cc616877d7f0122b4547f4ccd6a6c13b61b2036 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3cc616877d7f0122b4547f4ccd6a6c13b61b2036/tokio/src/time/clock.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/clock.rs:3 | /// println!("Hello world");
/// }
/// ```
///
/// # Panics
///
/// Panics if time is already frozen or if called from outside of a
/// `current_thread` Tokio runtime.
///
/// # Auto-advance
///
/// If time is paused and the runtime has no work to do, the clock is
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 3cc616877d7f0122b4547f4ccd6a6c13b61b2036 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3cc616877d7f0122b4547f4ccd6a6c13b61b2036/tokio/src/time/clock.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/clock.rs:4 | }
inner.unfrozen = Some(std::time::Instant::now());
}
/// Advances time.
///
/// Increments the saved `Instant::now()` value by `duration`. Subsequent
/// calls to `Instant::now()` will return the result of the increment.
///
/// This function will make the current time jump forwar... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 3cc616877d7f0122b4547f4ccd6a6c13b61b2036 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3cc616877d7f0122b4547f4ccd6a6c13b61b2036/tokio/src/time/clock.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/clock.rs:5 | crate::task::yield_now().await;
}
/// Returns the current instant, factoring in frozen time.
pub(crate) fn now() -> Instant {
if let Some(clock) = clock() {
clock.now()
} else {
Instant::from_std(std::time::Instant::now())
}
}
impl Clock {
//... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 3cc616877d7f0122b4547f4ccd6a6c13b61b2036 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3cc616877d7f0122b4547f4ccd6a6c13b61b2036/tokio/src/time/clock.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/time/clock.rs:6 | This is the default Runtime used by `#[tokio::test].");
}
let elapsed = inner.unfrozen.as_ref().expect("time is already frozen").elapsed();
inner.base += elapsed;
inner.unfrozen = None;
}
pub(crate) fn is_paused(&self) -> bool {
let inner = s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 3cc616877d7f0122b4547f4ccd6a6c13b61b2036 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/3cc616877d7f0122b4547f4ccd6a6c13b61b2036/tokio/src/time/clock.rs | 201 | 237 |
tokio-rs/tokio:tokio/src/time/clock.rs:2 | fn clock() -> Option<Clock> {
None
}
}
/// A handle to a source of time.
#[derive(Debug, Clone)]
pub(crate) struct Clock {
inner: Arc<Mutex<Inner>>,
}
#[derive(Debug)]
struct Inner {
/// True if the ability to pause time is enabled.
enable_pausin... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/time/clock.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/clock.rs:4 | inner.unfrozen = Some(std::time::Instant::now());
}
/// Advances time.
///
/// Increments the saved `Instant::now()` value by `duration`. Subsequent
/// calls to `Instant::now()` will return the result of the increment.
///
/// This function will make the current time jump forward by the gi... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/time/clock.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/clock.rs:5 | /// Returns the current instant, factoring in frozen time.
pub(crate) fn now() -> Instant {
if let Some(clock) = clock() {
clock.now()
} else {
Instant::from_std(std::time::Instant::now())
}
}
impl Clock {
/// Returns a new `Clock` instance that uses ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/time/clock.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/time/clock.rs:6 | let elapsed = inner.unfrozen.as_ref().expect("time is already frozen").elapsed();
inner.base += elapsed;
inner.unfrozen = None;
}
pub(crate) fn is_paused(&self) -> bool {
let inner = self.inner.lock();
inner.unfrozen.is_none()
}
pub(crate... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/time/clock.rs | 201 | 233 |
tokio-rs/tokio:tokio/src/time/clock.rs:1 | #![cfg_attr(not(feature = "rt"), allow(dead_code))]
//! Source of time abstraction.
//!
//! By default, `std::time::Instant::now()` is used. However, when the
//! `test-util` feature flag is enabled, the values returned for `now()` are
//! configurable.
cfg_not_test_util! {
use crate::time::{Instant};
#[deri... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | ab34805849fb8c44b9e2674ccc4dcca11b77ee8c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ab34805849fb8c44b9e2674ccc4dcca11b77ee8c/tokio/src/time/clock.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/clock.rs:2 | fn clock() -> Option<Clock> {
None
}
}
/// A handle to a source of time.
#[derive(Debug, Clone)]
pub(crate) struct Clock {
inner: Arc<Mutex<Inner>>,
}
#[derive(Debug)]
struct Inner {
/// True if the ability to pause time is enabled.
enable_pausin... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | ab34805849fb8c44b9e2674ccc4dcca11b77ee8c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ab34805849fb8c44b9e2674ccc4dcca11b77ee8c/tokio/src/time/clock.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/clock.rs:4 | inner.unfrozen = Some(std::time::Instant::now());
}
/// Advance time.
///
/// Increments the saved `Instant::now()` value by `duration`. Subsequent
/// calls to `Instant::now()` will return the result of the increment.
///
/// This function will make the current time jump forward by the giv... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | ab34805849fb8c44b9e2674ccc4dcca11b77ee8c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ab34805849fb8c44b9e2674ccc4dcca11b77ee8c/tokio/src/time/clock.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/clock.rs:5 | /// Return the current instant, factoring in frozen time.
pub(crate) fn now() -> Instant {
if let Some(clock) = clock() {
clock.now()
} else {
Instant::from_std(std::time::Instant::now())
}
}
impl Clock {
/// Return a new `Clock` instance that uses th... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | ab34805849fb8c44b9e2674ccc4dcca11b77ee8c | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ab34805849fb8c44b9e2674ccc4dcca11b77ee8c/tokio/src/time/clock.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/time/clock.rs:4 | inner.unfrozen = Some(std::time::Instant::now());
}
/// Advance time
///
/// Increments the saved `Instant::now()` value by `duration`. Subsequent
/// calls to `Instant::now()` will return the result of the increment.
///
/// Although this function is async, it does not wait for timers with... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 6778a7def6a7772e4f41eaf1a2bae275c33d3e4d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6778a7def6a7772e4f41eaf1a2bae275c33d3e4d/tokio/src/time/clock.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/clock.rs:5 | impl Clock {
/// Return a new `Clock` instance that uses the current execution context's
/// source of time.
pub(crate) fn new(enable_pausing: bool, start_paused: bool) -> Clock {
let now = std::time::Instant::now();
let clock = Clock {
inner: Arc::new(Mu... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 6778a7def6a7772e4f41eaf1a2bae275c33d3e4d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6778a7def6a7772e4f41eaf1a2bae275c33d3e4d/tokio/src/time/clock.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/time/clock.rs:6 | pub(crate) fn advance(&self, duration: Duration) {
let mut inner = self.inner.lock();
if inner.unfrozen.is_some() {
panic!("time is not frozen");
}
inner.base += duration;
}
pub(crate) fn now(&self) -> Instant {
let inner = s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 6778a7def6a7772e4f41eaf1a2bae275c33d3e4d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6778a7def6a7772e4f41eaf1a2bae275c33d3e4d/tokio/src/time/clock.rs | 201 | 224 |
tokio-rs/tokio:tokio/src/time/clock.rs:2 | fn clock() -> Option<Clock> {
None
}
}
/// A handle to a source of time.
#[derive(Debug, Clone)]
pub(crate) struct Clock {
inner: Arc<Mutex<Inner>>,
}
#[derive(Debug)]
struct Inner {
/// True if the ability to pause time is enabled.
enable_pausin... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 549e89e9cd2073ffa70f1bd12022c5543343be78 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/549e89e9cd2073ffa70f1bd12022c5543343be78/tokio/src/time/clock.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/clock.rs:3 | /// # Auto-advance
///
/// If time is paused and the runtime has no work to do, the clock is
/// auto-advanced to the next pending timer. This means that [`Sleep`] or
/// other timer-backed primitives can cause the runtime to advance the
/// current time when awaited.
///
/// [`Sleep`]: crat... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 549e89e9cd2073ffa70f1bd12022c5543343be78 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/549e89e9cd2073ffa70f1bd12022c5543343be78/tokio/src/time/clock.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/clock.rs:4 | /// Panics if time is not frozen or if called from outside of the Tokio
/// runtime.
///
/// # Auto-advance
///
/// If the time is paused and there is no work to do, the runtime advances
/// time to the next timer. See [`pause`](pause#auto-advance) for more
/// details.
pub async fn adva... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 549e89e9cd2073ffa70f1bd12022c5543343be78 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/549e89e9cd2073ffa70f1bd12022c5543343be78/tokio/src/time/clock.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/clock.rs:5 | }
clock
}
pub(crate) fn pause(&self) {
let mut inner = self.inner.lock();
if !inner.enable_pausing {
drop(inner); // avoid poisoning the lock
panic!("`time::pause()` requires the `current_thread` Tokio runtime. \
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 549e89e9cd2073ffa70f1bd12022c5543343be78 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/549e89e9cd2073ffa70f1bd12022c5543343be78/tokio/src/time/clock.rs | 161 | 207 |
tokio-rs/tokio:tokio/src/time/clock.rs:1 | #![cfg_attr(not(feature = "rt"), allow(dead_code))]
//! Source of time abstraction.
//!
//! By default, `std::time::Instant::now()` is used. However, when the
//! `test-util` feature flag is enabled, the values returned for `now()` are
//! configurable.
cfg_not_test_util! {
use crate::time::{Instant};
#[deri... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 5ad3dd337899c791a6e35e83dbf0fa7ca0edf605 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5ad3dd337899c791a6e35e83dbf0fa7ca0edf605/tokio/src/time/clock.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/clock.rs:3 | /// # Auto-advance
///
/// If time is paused and the runtime has no work to do, the clock is
/// auto-advanced to the next pending timer. This means that [`Sleep`] or
/// other timer-backed primitives can cause the runtime to advance the
/// current time when awaited.
///
/// [`Sleep`]: crat... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 5ad3dd337899c791a6e35e83dbf0fa7ca0edf605 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5ad3dd337899c791a6e35e83dbf0fa7ca0edf605/tokio/src/time/clock.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/clock.rs:4 | /// Panics if time is not frozen or if called from outside of the Tokio
/// runtime.
///
/// # Auto-advance
///
/// If the time is paused and there is no work to do, the runtime advances
/// time to the next timer. See [`pause`](pause#auto-advance) for more
/// details.
pub async fn adva... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 5ad3dd337899c791a6e35e83dbf0fa7ca0edf605 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5ad3dd337899c791a6e35e83dbf0fa7ca0edf605/tokio/src/time/clock.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/clock.rs:5 | }
clock
}
pub(crate) fn pause(&self) {
let mut inner = self.inner.lock().unwrap();
if !inner.enable_pausing {
drop(inner); // avoid poisoning the lock
panic!("`time::pause()` requires the `current_thread` Tokio runtime. \
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 5ad3dd337899c791a6e35e83dbf0fa7ca0edf605 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/5ad3dd337899c791a6e35e83dbf0fa7ca0edf605/tokio/src/time/clock.rs | 161 | 207 |
tokio-rs/tokio:tokio/src/time/clock.rs:2 | fn clock() -> Option<Clock> {
None
}
}
/// A handle to a source of time.
#[derive(Debug, Clone)]
pub(crate) struct Clock {
inner: Arc<Mutex<Inner>>,
}
#[derive(Debug)]
struct Inner {
/// True if the ability to pause time is enabled.
enable_pausin... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 18779aa2e292c4c060a35c2882601373c36e7af0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/18779aa2e292c4c060a35c2882601373c36e7af0/tokio/src/time/clock.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/clock.rs:3 | let clock = clock().expect("time cannot be frozen from outside the Tokio runtime");
clock.pause();
}
/// Resume time
///
/// Clears the saved `Instant::now()` value. Subsequent calls to
/// `Instant::now()` will return the value returned by the system call.
///
/// # Panics
///
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 18779aa2e292c4c060a35c2882601373c36e7af0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/18779aa2e292c4c060a35c2882601373c36e7af0/tokio/src/time/clock.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/clock.rs:4 | /// Return the current instant, factoring in frozen time.
pub(crate) fn now() -> Instant {
if let Some(clock) = clock() {
clock.now()
} else {
Instant::from_std(std::time::Instant::now())
}
}
impl Clock {
/// Return a new `Clock` instance that uses th... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 18779aa2e292c4c060a35c2882601373c36e7af0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/18779aa2e292c4c060a35c2882601373c36e7af0/tokio/src/time/clock.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/clock.rs:5 | inner.base += elapsed;
inner.unfrozen = None;
}
pub(crate) fn is_paused(&self) -> bool {
let inner = self.inner.lock().unwrap();
inner.unfrozen.is_none()
}
pub(crate) fn advance(&self, duration: Duration) {
let mut inner = self.inner.lock... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 18779aa2e292c4c060a35c2882601373c36e7af0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/18779aa2e292c4c060a35c2882601373c36e7af0/tokio/src/time/clock.rs | 161 | 192 |
tokio-rs/tokio:tokio/src/time/clock.rs:1 | #![cfg_attr(not(feature = "rt"), allow(dead_code))]
//! Source of time abstraction.
//!
//! By default, `std::time::Instant::now()` is used. However, when the
//! `test-util` feature flag is enabled, the values returned for `now()` are
//! configurable.
cfg_not_test_util! {
use crate::time::{Duration, Instant};
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 2b9b55810847b4c7855e3de82f432ca997600f30 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2b9b55810847b4c7855e3de82f432ca997600f30/tokio/src/time/clock.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/clock.rs:2 | cfg_rt! {
fn clock() -> Option<Clock> {
crate::runtime::context::clock()
}
}
cfg_not_rt! {
fn clock() -> Option<Clock> {
None
}
}
/// A handle to a source of time.
#[derive(Debug, Clone)]
pub(crate) struct Clock {
inner: Arc<Mutex... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 2b9b55810847b4c7855e3de82f432ca997600f30 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2b9b55810847b4c7855e3de82f432ca997600f30/tokio/src/time/clock.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/clock.rs:3 | /// default runtime used by `#[tokio::test]`. The runtime can be initialized
/// with time in a paused state using the `Builder::start_paused` method.
///
/// # Panics
///
/// Panics if time is already frozen or if called from outside of a
/// `current_thread` Tokio runtime.
pub fn pause() {... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 2b9b55810847b4c7855e3de82f432ca997600f30 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2b9b55810847b4c7855e3de82f432ca997600f30/tokio/src/time/clock.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/clock.rs:4 | /// runtime.
pub async fn advance(duration: Duration) {
let clock = clock().expect("time cannot be frozen from outside the Tokio runtime");
let until = clock.now() + duration;
clock.advance(duration);
crate::time::sleep_until(until).await;
}
/// Return the current instant, ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 2b9b55810847b4c7855e3de82f432ca997600f30 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2b9b55810847b4c7855e3de82f432ca997600f30/tokio/src/time/clock.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/clock.rs:5 | let mut inner = self.inner.lock().unwrap();
if !inner.enable_pausing {
drop(inner); // avoid poisoning the lock
panic!("`time::pause()` requires the `current_thread` Tokio runtime. \
This is the default Runtime used by `#[tokio::test].");
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 2b9b55810847b4c7855e3de82f432ca997600f30 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2b9b55810847b4c7855e3de82f432ca997600f30/tokio/src/time/clock.rs | 161 | 201 |
tokio-rs/tokio:tokio/src/time/clock.rs:3 | /// default runtime used by `#[tokio::test]`. The runtime can be initialized
/// with time in a paused state using the `Builder::start_paused` method.
///
/// # Panics
///
/// Panics if time is already frozen or if called from outside of a
/// `current_thread` Tokio runtime.
pub fn pause() {... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | fcb6d041b9d2fe567b5306e648cbb048b426a49d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fcb6d041b9d2fe567b5306e648cbb048b426a49d/tokio/src/time/clock.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/clock.rs:4 | /// runtime.
pub async fn advance(duration: Duration) {
use crate::future::poll_fn;
use std::task::Poll;
let clock = clock().expect("time cannot be frozen from outside the Tokio runtime");
clock.advance(duration);
let mut yielded = false;
poll_fn(|cx| {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | fcb6d041b9d2fe567b5306e648cbb048b426a49d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fcb6d041b9d2fe567b5306e648cbb048b426a49d/tokio/src/time/clock.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/clock.rs:5 | })),
};
if start_paused {
clock.pause();
}
clock
}
pub(crate) fn pause(&self) {
let mut inner = self.inner.lock().unwrap();
if !inner.enable_pausing {
drop(inner); // avoid poisoning the lock
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | fcb6d041b9d2fe567b5306e648cbb048b426a49d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fcb6d041b9d2fe567b5306e648cbb048b426a49d/tokio/src/time/clock.rs | 161 | 212 |
tokio-rs/tokio:tokio/src/time/clock.rs:6 | let inner = self.inner.lock().unwrap();
let mut ret = inner.base;
if let Some(unfrozen) = inner.unfrozen {
ret += unfrozen.elapsed();
}
Instant::from_std(ret)
}
}
} | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | fcb6d041b9d2fe567b5306e648cbb048b426a49d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/fcb6d041b9d2fe567b5306e648cbb048b426a49d/tokio/src/time/clock.rs | 201 | 212 |
tokio-rs/tokio:tokio/src/time/clock.rs:1 | #![cfg_attr(not(feature = "rt"), allow(dead_code))]
//! Source of time abstraction.
//!
//! By default, `std::time::Instant::now()` is used. However, when the
//! `test-util` feature flag is enabled, the values returned for `now()` are
//! configurable.
cfg_not_test_util! {
use crate::time::{Duration, Instant};
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | abd4c0025539f142ec48a09e01430f7ee3b83214 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/abd4c0025539f142ec48a09e01430f7ee3b83214/tokio/src/time/clock.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/clock.rs:2 | cfg_rt! {
fn clock() -> Option<Clock> {
crate::runtime::context::clock()
}
}
cfg_not_rt! {
fn clock() -> Option<Clock> {
None
}
}
/// A handle to a source of time.
#[derive(Debug, Clone)]
pub(crate) struct Clock {
inner: Arc<Mutex... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | abd4c0025539f142ec48a09e01430f7ee3b83214 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/abd4c0025539f142ec48a09e01430f7ee3b83214/tokio/src/time/clock.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/clock.rs:3 | /// default runtime used by `#[tokio::test]`
///
/// # Panics
///
/// Panics if time is already frozen or if called from outside of a
/// `current_thread` Tokio runtime.
pub fn pause() {
let clock = clock().expect("time cannot be frozen from outside the Tokio runtime");
clock.pau... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | abd4c0025539f142ec48a09e01430f7ee3b83214 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/abd4c0025539f142ec48a09e01430f7ee3b83214/tokio/src/time/clock.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/clock.rs:4 | pub async fn advance(duration: Duration) {
use crate::future::poll_fn;
use std::task::Poll;
let clock = clock().expect("time cannot be frozen from outside the Tokio runtime");
clock.advance(duration);
let mut yielded = false;
poll_fn(|cx| {
if yielded {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | abd4c0025539f142ec48a09e01430f7ee3b83214 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/abd4c0025539f142ec48a09e01430f7ee3b83214/tokio/src/time/clock.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/clock.rs:5 | }
}
pub(crate) fn pause(&self) {
let mut inner = self.inner.lock().unwrap();
if !inner.enable_pausing {
drop(inner); // avoid poisoning the lock
panic!("`time::pause()` requires the `current_thread` Tokio runtime. \
This i... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | abd4c0025539f142ec48a09e01430f7ee3b83214 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/abd4c0025539f142ec48a09e01430f7ee3b83214/tokio/src/time/clock.rs | 161 | 205 |
tokio-rs/tokio:tokio/src/time/clock.rs:1 | #![cfg_attr(not(feature = "rt"), allow(dead_code))]
//! Source of time abstraction.
//!
//! By default, `std::time::Instant::now()` is used. However, when the
//! `test-util` feature flag is enabled, the values returned for `now()` are
//! configurable.
cfg_not_test_util! {
use crate::time::{Duration, Instant};
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | c90681bd8e629b5fde988b9f5be7b915e5cf8ae5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c90681bd8e629b5fde988b9f5be7b915e5cf8ae5/tokio/src/time/clock.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/clock.rs:2 | cfg_rt! {
fn clock() -> Option<Clock> {
crate::runtime::context::clock()
}
}
cfg_not_rt! {
fn clock() -> Option<Clock> {
None
}
}
/// A handle to a source of time.
#[derive(Debug, Clone)]
pub(crate) struct Clock {
inner: Arc<Mutex... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | c90681bd8e629b5fde988b9f5be7b915e5cf8ae5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c90681bd8e629b5fde988b9f5be7b915e5cf8ae5/tokio/src/time/clock.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/clock.rs:3 | let clock = clock().expect("time cannot be frozen from outside the Tokio runtime");
clock.pause();
}
/// Resume time
///
/// Clears the saved `Instant::now()` value. Subsequent calls to
/// `Instant::now()` will return the value returned by the system call.
///
/// # Panics
///
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | c90681bd8e629b5fde988b9f5be7b915e5cf8ae5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c90681bd8e629b5fde988b9f5be7b915e5cf8ae5/tokio/src/time/clock.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/clock.rs:4 | let mut yielded = false;
poll_fn(|cx| {
if yielded {
Poll::Ready(())
} else {
yielded = true;
cx.waker().wake_by_ref();
Poll::Pending
}
}).await;
}
/// Return the current instant, factoring in fr... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | c90681bd8e629b5fde988b9f5be7b915e5cf8ae5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c90681bd8e629b5fde988b9f5be7b915e5cf8ae5/tokio/src/time/clock.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/clock.rs:5 | inner.unfrozen = None;
}
pub(crate) fn is_paused(&self) -> bool {
let inner = self.inner.lock().unwrap();
inner.unfrozen.is_none()
}
pub(crate) fn advance(&self, duration: Duration) {
let mut inner = self.inner.lock().unwrap();
if inner.... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | c90681bd8e629b5fde988b9f5be7b915e5cf8ae5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c90681bd8e629b5fde988b9f5be7b915e5cf8ae5/tokio/src/time/clock.rs | 161 | 191 |
tokio-rs/tokio:tokio/src/time/clock.rs:1 | #![cfg_attr(not(feature = "rt-core"), allow(dead_code))]
//! Source of time abstraction.
//!
//! By default, `std::time::Instant::now()` is used. However, when the
//! `test-util` feature flag is enabled, the values returned for `now()` are
//! configurable.
cfg_not_test_util! {
use crate::time::{Duration, Instan... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 8880222036f37c6204c8466f25e828447f16dacb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8880222036f37c6204c8466f25e828447f16dacb/tokio/src/time/clock.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/clock.rs:2 | cfg_rt_core! {
fn clock() -> Option<Clock> {
crate::runtime::context::clock()
}
}
cfg_not_rt_core! {
fn clock() -> Option<Clock> {
None
}
}
/// A handle to a source of time.
#[derive(Debug, Clone)]
pub(crate) struct Clock {
inner:... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 8880222036f37c6204c8466f25e828447f16dacb | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8880222036f37c6204c8466f25e828447f16dacb/tokio/src/time/clock.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/clock.rs:1 | //! Source of time abstraction.
//!
//! By default, `std::time::Instant::now()` is used. However, when the
//! `test-util` feature flag is enabled, the values returned for `now()` are
//! configurable.
cfg_not_test_util! {
use crate::time::{Duration, Instant};
#[derive(Debug, Clone)]
pub(crate) struct Clo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 60d81bbe10faf344ea18438a1c5ecb9173e6ec52 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/60d81bbe10faf344ea18438a1c5ecb9173e6ec52/tokio/src/time/clock.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/clock.rs:2 | /// A handle to a source of time.
#[derive(Debug, Clone)]
pub(crate) struct Clock {
inner: Arc<Mutex<Inner>>,
}
#[derive(Debug)]
struct Inner {
/// Instant to use as the clock's base instant.
base: std::time::Instant,
/// Instant at which the clock was last unfrozen... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 60d81bbe10faf344ea18438a1c5ecb9173e6ec52 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/60d81bbe10faf344ea18438a1c5ecb9173e6ec52/tokio/src/time/clock.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/clock.rs:3 | pub fn resume() {
let clock = context::clock().expect("time cannot be frozen from outside the Tokio runtime");
let mut inner = clock.inner.lock().unwrap();
if inner.unfrozen.is_some() {
panic!("time is not frozen");
}
inner.unfrozen = Some(std::time::Instant::now())... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 60d81bbe10faf344ea18438a1c5ecb9173e6ec52 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/60d81bbe10faf344ea18438a1c5ecb9173e6ec52/tokio/src/time/clock.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/clock.rs:4 | Clock {
inner: Arc::new(Mutex::new(Inner {
base: now,
unfrozen: Some(now),
})),
}
}
pub(crate) fn pause(&self) {
let mut inner = self.inner.lock().unwrap();
let elapsed = inner.unfrozen.as_ref()... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 60d81bbe10faf344ea18438a1c5ecb9173e6ec52 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/60d81bbe10faf344ea18438a1c5ecb9173e6ec52/tokio/src/time/clock.rs | 121 | 165 |
tokio-rs/tokio:tokio/src/time/clock.rs:2 | /// A handle to a source of time.
#[derive(Debug, Clone)]
pub(crate) struct Clock {
inner: Arc<Mutex<Inner>>,
}
#[derive(Debug)]
struct Inner {
/// Instant to use as the clock's base instant.
base: std::time::Instant,
/// Instant at which the clock was last unfrozen... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | f69e5bfb87eda2b8de9b762b9280f1733cdaa096 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f69e5bfb87eda2b8de9b762b9280f1733cdaa096/tokio/src/time/clock.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/clock.rs:1 | //! Source of time abstraction.
//!
//! By default, `std::time::Instant::now()` is used. However, when the
//! `test-util` feature flag is enabled, the values returned for `now()` are
//! configurable.
cfg_not_test_util! {
use crate::time::{Duration, Instant};
#[derive(Debug, Clone)]
pub(crate) struct Clo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 57ba37c97854d32e691ea68006c8d69d58c79b23 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/57ba37c97854d32e691ea68006c8d69d58c79b23/tokio/src/time/clock.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/clock.rs:2 | /// A handle to a source of time.
#[derive(Debug, Clone)]
pub(crate) struct Clock {
inner: Arc<Mutex<Inner>>,
}
#[derive(Debug)]
struct Inner {
/// Instant to use as the clock's base instant.
base: std::time::Instant,
/// Instant at which the clock was last unfrozen... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 57ba37c97854d32e691ea68006c8d69d58c79b23 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/57ba37c97854d32e691ea68006c8d69d58c79b23/tokio/src/time/clock.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/clock.rs:3 | let clock = context::clock().expect("time cannot be frozen from outside the Tokio runtime");
let mut inner = clock.inner.lock().unwrap();
if inner.unfrozen.is_some() {
panic!("time is not frozen");
}
inner.unfrozen = Some(std::time::Instant::now());
}
/// Advance t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 57ba37c97854d32e691ea68006c8d69d58c79b23 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/57ba37c97854d32e691ea68006c8d69d58c79b23/tokio/src/time/clock.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/clock.rs:1 | //! Source of time abstraction.
//!
//! By default, `std::time::Instant::now()` is used. However, when the
//! `test-util` feature flag is enabled, the values returned for `now()` are
//! configurable.
cfg_not_test_util! {
use crate::time::{Duration, Instant};
#[derive(Debug, Clone)]
pub(crate) struct Clo... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 45da5f3510a61599c89dc458ecc859f13a81e255 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/45da5f3510a61599c89dc458ecc859f13a81e255/tokio/src/time/clock.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/clock.rs:2 | /// A handle to a source of time.
#[derive(Debug, Clone)]
pub(crate) struct Clock {
inner: Arc<Inner>,
}
#[derive(Debug)]
struct Inner {
/// Instant at which the clock was created
start: std::time::Instant,
/// Current, "frozen" time as an offset from `start`.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 45da5f3510a61599c89dc458ecc859f13a81e255 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/45da5f3510a61599c89dc458ecc859f13a81e255/tokio/src/time/clock.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/clock.rs:3 | ///
/// Panics if time is not frozen or if called from outside of the Tokio
/// runtime.
pub fn resume() {
let clock = context::clock().expect("time cannot be frozen from outside the Tokio runtime");
let mut frozen = clock.inner.frozen.lock().unwrap();
if frozen.is_none() {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 45da5f3510a61599c89dc458ecc859f13a81e255 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/45da5f3510a61599c89dc458ecc859f13a81e255/tokio/src/time/clock.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/clock.rs:4 | }
impl Clock {
/// Return a new `Clock` instance that uses the current execution context's
/// source of time.
pub(crate) fn new() -> Clock {
Clock {
inner: Arc::new(Inner {
start: std::time::Instant::now(),
frozen: Mutex::... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 45da5f3510a61599c89dc458ecc859f13a81e255 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/45da5f3510a61599c89dc458ecc859f13a81e255/tokio/src/time/clock.rs | 121 | 176 |
tokio-rs/tokio:tokio/src/time/clock.rs:5 | // TODO: delete this as well
#[cfg(all(test, not(loom)))]
pub(crate) fn advanced(&self) -> Duration {
self.inner.frozen.lock().unwrap().unwrap()
}
pub(crate) fn now(&self) -> Instant {
Instant::from_std(if let Some(frozen) = *self.inner.frozen.lock().unwrap() {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 45da5f3510a61599c89dc458ecc859f13a81e255 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/45da5f3510a61599c89dc458ecc859f13a81e255/tokio/src/time/clock.rs | 161 | 176 |
tokio-rs/tokio:tokio/src/time/clock.rs:2 | /// A handle to a source of time.
#[derive(Debug, Clone)]
pub(crate) struct Clock {
inner: Arc<Inner>,
}
#[derive(Debug)]
struct Inner {
/// Instant at which the clock was created
start: std::time::Instant,
/// Current, "frozen" time as an offset from `start`.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | f0006006ed9938115011c42f26cff16842eb534f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f0006006ed9938115011c42f26cff16842eb534f/tokio/src/time/clock.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/clock.rs:3 | ///
/// Panics if time is not frozen or if called from outside of the Tokio
/// runtime.
pub fn resume() {
let clock = context::ThreadContext::clock().expect("time cannot be frozen from outside the Tokio runtime");
let mut frozen = clock.inner.frozen.lock().unwrap();
if frozen.is_no... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | f0006006ed9938115011c42f26cff16842eb534f | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f0006006ed9938115011c42f26cff16842eb534f/tokio/src/time/clock.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/clock.rs:1 | //! Source of time abstraction.
//!
//! By default, `std::time::Instant::now()` is used. However, when the
//! `test-util` feature flag is enabled, the values returned for `now()` are
//! configurable.
cfg_not_test_util! {
use crate::time::Instant;
#[derive(Debug, Clone)]
pub(crate) struct Clock {}
p... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 67bf9c36f347031ca05872d102a7f9abc8b465f0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/67bf9c36f347031ca05872d102a7f9abc8b465f0/tokio/src/time/clock.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/clock.rs:2 | /// Instant at which the clock was created
start: std::time::Instant,
/// Current, "frozen" time as an offset from `start`.
frozen: Mutex<Option<Duration>>,
}
/// Pause time
///
/// The current value of `Instant::now()` is saved and all subsequent calls
/// to `Instant::now... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 67bf9c36f347031ca05872d102a7f9abc8b465f0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/67bf9c36f347031ca05872d102a7f9abc8b465f0/tokio/src/time/clock.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/clock.rs:3 | panic!("time is not frozen");
}
*frozen = None;
}
/// Advance time
///
/// Increments the saved `Instant::now()` value by `duration`. Subsequent
/// calls to `Instant::now()` will return the result of the increment.
///
/// # Panics
///
/// Panics if time is not fro... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/clock.rs | MIT | 67bf9c36f347031ca05872d102a7f9abc8b465f0 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/67bf9c36f347031ca05872d102a7f9abc8b465f0/tokio/src/time/clock.rs | 81 | 140 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.