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/tests/test_delay.rs:5 | // Turn the timer with a smaller timeout than the cascade.
clock.turn_for(ms(100));
assert_eq!(clock.advanced(), ms(100));
assert_pending!(fut.poll());
// Turn the timer, this will wake up to cascade the timer down.
clock.turn_for(ms(1000));
assert_eq!(clock.advanced(),... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_delay.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/tests/test_delay.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/time/tests/test_delay.rs:6 | clock.turn_for(ms(1000));
assert_eq!(clock.advanced(), ms(500));
// The delay has elapsed
assert_ready!(fut.poll());
});
}
#[test]
fn concurrently_set_two_timers_second_one_shorter() {
mock(|clock| {
let mut fut1 = task::spawn(delay_until(clock.now() + ms(500)));
let mu... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_delay.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/tests/test_delay.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/time/tests/test_delay.rs:7 | })
}
#[test]
fn short_delay() {
mock(|clock| {
// Create a `Delay` that elapses in the future
let mut fut = task::spawn(delay_until(clock.now() + ms(1)));
// The delay has not elapsed.
assert_pending!(fut.poll());
// Turn the timer, but not enough time will go by.
... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_delay.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/tests/test_delay.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/time/tests/test_delay.rs:8 | assert_pending!(fut.poll());
}
clock.turn();
assert_eq!(clock.advanced(), ms(MIN_5));
// The delay has elapsed.
assert_ready!(fut.poll());
})
}
#[test]
fn very_long_delay() {
const MO_5: u64 = 5 * 30 * 24 * 60 * 60 * 1000;
mock(|clock| {
// Create a `Delay... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_delay.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/tests/test_delay.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/time/tests/test_delay.rs:9 | assert_eq!(clock.advanced(), ms(MO_5));
// The delay has elapsed.
assert_ready!(fut.poll());
})
}
#[test]
#[should_panic]
fn greater_than_max() {
const YR_5: u64 = 5 * 365 * 24 * 60 * 60 * 1000;
mock(|clock| {
// Create a `Delay` that elapses in the future
let mut fut = ta... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_delay.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/tests/test_delay.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/time/tests/test_delay.rs:10 | assert_ready!(fut1.poll());
assert_ready!(fut2.poll());
assert_ready!(fut3.poll());
})
}
#[test]
fn set_timeout_at_deadline_greater_than_max_timer() {
const YR_1: u64 = 365 * 24 * 60 * 60 * 1000;
const YR_5: u64 = 5 * YR_1;
mock(|clock| {
for _ in 0..5 {
clock.turn_... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_delay.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/tests/test_delay.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/time/tests/test_delay.rs:11 | clock.turn();
assert_eq!(clock.advanced(), ms(200));
assert_ready!(fut.poll());
});
}
#[test]
fn reset_past_delay_before_turn() {
mock(|clock| {
let mut fut = task::spawn(delay_until(clock.now() + ms(100)));
assert_pending!(fut.poll());
fut.reset(clock.now() + ms(80))... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_delay.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/tests/test_delay.rs | 401 | 460 |
tokio-rs/tokio:tokio/src/time/tests/test_delay.rs:12 | assert_eq!(clock.advanced(), ms(64));
assert_pending!(fut.poll());
clock.turn();
assert_eq!(clock.advanced(), ms(90));
assert_ready!(fut.poll());
});
}
#[test]
fn reset_future_delay_after_fire() {
mock(|clock| {
let mut fut = task::spawn(delay_until(clock.now() + ms(1... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_delay.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/tests/test_delay.rs | 441 | 479 |
tokio-rs/tokio:tokio/src/time/tests/test_queue.rs:1 | #![warn(rust_2018_idioms)]
use crate::time::tests::mock_clock::mock;
use crate::time::{DelayQueue, Duration};
use tokio_test::{assert_ok, assert_pending, assert_ready, task};
macro_rules! poll {
($queue:ident) => {
$queue.enter(|cx, mut queue| queue.poll_expired(cx))
};
}
macro_rules! assert_ready_ok... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_queue.rs | MIT | d593c5b051f07bde5117122216a356632986b6dd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d593c5b051f07bde5117122216a356632986b6dd/tokio/src/time/tests/test_queue.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/tests/test_queue.rs:2 | let _k = queue.insert_at("1", clock.now());
let _k = queue.insert_at("2", clock.now());
let _k = queue.insert_at("3", clock.now());
let mut res = vec![];
while res.len() < 3 {
let entry = assert_ready_ok!(poll!(queue));
res.push(entry.into_inner());
}
... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_queue.rs | MIT | d593c5b051f07bde5117122216a356632986b6dd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d593c5b051f07bde5117122216a356632986b6dd/tokio/src/time/tests/test_queue.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/tests/test_queue.rs:3 | let entry = assert_ready!(poll!(queue));
assert!(entry.is_none());
});
}
#[test]
fn multi_delay_at_start() {
let long = 262_144 + 9 * 4096;
let delays = &[1000, 2, 234, long, 60, 10];
mock(|clock| {
let mut queue = task::spawn(DelayQueue::new());
// Setup the delays
fo... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_queue.rs | MIT | d593c5b051f07bde5117122216a356632986b6dd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d593c5b051f07bde5117122216a356632986b6dd/tokio/src/time/tests/test_queue.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/tests/test_queue.rs:4 | #[test]
fn insert_in_past_fires_immediately() {
mock(|clock| {
let mut queue = task::spawn(DelayQueue::new());
let now = clock.now();
clock.turn_for(ms(10));
queue.insert_at("foo", now);
assert_ready!(poll!(queue));
});
}
#[test]
fn remove_entry() {
mock(|clock| ... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_queue.rs | MIT | d593c5b051f07bde5117122216a356632986b6dd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d593c5b051f07bde5117122216a356632986b6dd/tokio/src/time/tests/test_queue.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/tests/test_queue.rs:5 | let key = queue.insert_at("foo", now + ms(5));
assert_pending!(poll!(queue));
clock.turn_for(ms(1));
queue.reset_at(&key, now + ms(10));
assert_pending!(poll!(queue));
clock.turn_for(ms(7));
assert!(!queue.is_woken());
assert_pending!(poll!(queue));
... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_queue.rs | MIT | d593c5b051f07bde5117122216a356632986b6dd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d593c5b051f07bde5117122216a356632986b6dd/tokio/src/time/tests/test_queue.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/time/tests/test_queue.rs:6 | clock.turn_for(ms(3));
queue.reset_at(&key, epoch + ms(5));
clock.turn_for(ms(20));
assert!(queue.is_woken());
});
}
#[test]
fn reset_twice() {
// Reproduces tokio-rs/tokio#849.
mock(|clock| {
let mut queue = task::spawn(DelayQueue::new());
let epoch = clock.now(... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_queue.rs | MIT | d593c5b051f07bde5117122216a356632986b6dd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d593c5b051f07bde5117122216a356632986b6dd/tokio/src/time/tests/test_queue.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/time/tests/test_queue.rs:7 | fn remove_expired_item() {
mock(|clock| {
let mut queue = DelayQueue::new();
let now = clock.now();
clock.turn_for(ms(10));
let key = queue.insert_at("foo", now);
let entry = queue.remove(&key);
assert_eq!(entry.into_inner(), "foo");
})
}
#[test]
fn expires_b... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_queue.rs | MIT | d593c5b051f07bde5117122216a356632986b6dd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d593c5b051f07bde5117122216a356632986b6dd/tokio/src/time/tests/test_queue.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/time/tests/test_queue.rs:8 | #[test]
fn multi_reset() {
mock(|clock| {
let mut queue = task::spawn(DelayQueue::new());
let epoch = clock.now();
let one = queue.insert_at("one", epoch + ms(200));
let two = queue.insert_at("two", epoch + ms(250));
assert_pending!(poll!(queue));
queue.reset_at(&... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_queue.rs | MIT | d593c5b051f07bde5117122216a356632986b6dd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d593c5b051f07bde5117122216a356632986b6dd/tokio/src/time/tests/test_queue.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/time/tests/test_queue.rs:9 | }
#[test]
fn expire_second_key_when_reset_to_expire_earlier() {
mock(|clock| {
let mut queue = task::spawn(DelayQueue::new());
let epoch = clock.now();
queue.insert_at("one", epoch + ms(200));
let two = queue.insert_at("two", epoch + ms(250));
assert_pending!(poll!(queue)... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_queue.rs | MIT | d593c5b051f07bde5117122216a356632986b6dd | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d593c5b051f07bde5117122216a356632986b6dd/tokio/src/time/tests/test_queue.rs | 321 | 369 |
tokio-rs/tokio:tokio/src/time/tests/test_queue.rs:3 | let entry = assert_ready!(poll!(queue));
assert!(entry.is_none());
});
}
#[test]
fn multi_delay_at_start() {
let long = 262_144 + 9 * 4096;
let delays = &[1000, 2, 234, long, 60, 10];
mock(|clock| {
let mut queue = task::spawn(DelayQueue::new());
// Setup the delays
fo... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_queue.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/tests/test_queue.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/tests/test_queue.rs:4 | }
#[test]
fn insert_in_past_fires_immediately() {
mock(|clock| {
let mut queue = task::spawn(DelayQueue::new());
let now = clock.now();
clock.turn_for(ms(10));
queue.insert_at("foo", now);
assert_ready!(poll!(queue));
});
}
#[test]
fn remove_entry() {
mock(|cloc... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_queue.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/tests/test_queue.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/tests/test_queue.rs:5 | let now = clock.now();
let key = queue.insert_at("foo", now + ms(5));
assert_pending!(poll!(queue));
clock.turn_for(ms(1));
queue.reset_at(&key, now + ms(10));
assert_pending!(poll!(queue));
clock.turn_for(ms(7));
assert!(!queue.is_woken());
assert_p... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_queue.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/tests/test_queue.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/time/tests/test_queue.rs:6 | assert_pending!(poll!(queue));
clock.turn_for(ms(3));
queue.reset_at(&key, epoch + ms(5));
clock.turn_for(ms(20));
assert!(queue.is_woken());
});
}
#[test]
fn reset_twice() {
// Reproduces tokio-rs/tokio#849.
mock(|clock| {
let mut queue = task::spawn(DelayQueue:... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_queue.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/tests/test_queue.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/time/tests/test_queue.rs:7 | #[test]
fn remove_expired_item() {
mock(|clock| {
let mut queue = DelayQueue::new();
let now = clock.now();
clock.turn_for(ms(10));
let key = queue.insert_at("foo", now);
let entry = queue.remove(&key);
assert_eq!(entry.into_inner(), "foo");
})
}
#[test]
fn e... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_queue.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/tests/test_queue.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/time/tests/test_queue.rs:8 | })
}
#[test]
fn multi_reset() {
mock(|clock| {
let mut queue = task::spawn(DelayQueue::new());
let epoch = clock.now();
let foo = queue.insert_at("foo", epoch + ms(200));
let bar = queue.insert_at("bar", epoch + ms(250));
assert_pending!(poll!(queue));
queue.rese... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_queue.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/tests/test_queue.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/time/tests/test_queue.rs:9 | assert_eq!(entry, "foo");
})
}
#[test]
fn expire_second_key_when_reset_to_expire_earlier() {
mock(|clock| {
let mut queue = task::spawn(DelayQueue::new());
let epoch = clock.now();
queue.insert_at("foo", epoch + ms(200));
let bar = queue.insert_at("bar", epoch + ms(250));
... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_queue.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/tests/test_queue.rs | 321 | 371 |
tokio-rs/tokio:tokio/src/time/tests/test_queue.rs:10 | assert!(queue.is_woken());
let entry = assert_ready_ok!(poll!(queue)).into_inner();
assert_eq!(entry, "bar");
})
}
fn ms(n: u64) -> Duration {
Duration::from_millis(n)
} | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_queue.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/tests/test_queue.rs | 361 | 371 |
tokio-rs/tokio:tokio/src/time/tests/test_sleep.rs:1 | //use crate::time::driver::{Driver, Entry, Handle};
/*
macro_rules! poll {
($e:expr) => {
$e.enter(|cx, e| e.poll_elapsed(cx))
};
}
#[test]
fn frozen_utility_returns_correct_advanced_duration() {
let clock = Clock::new();
clock.pause();
let start = clock.now();
clock.advance(ms(10));
... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_sleep.rs | MIT | ae67851f11b7cc1f577de8ce21767ce3e2c7aff9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ae67851f11b7cc1f577de8ce21767ce3e2c7aff9/tokio/src/time/tests/test_sleep.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/tests/test_sleep.rs:2 | for &i in &[1, 10, 60] {
// Create a `Sleep` that elapses in the future
let mut e = task::spawn(sleep_until(&handle, start + ms(i)));
// The sleep instance has not elapsed.
assert_pending!(poll!(e));
assert_ok!(driver.park());
assert_eq!(clock.now() - start, ms(i));
... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_sleep.rs | MIT | ae67851f11b7cc1f577de8ce21767ce3e2c7aff9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ae67851f11b7cc1f577de8ce21767ce3e2c7aff9/tokio/src/time/tests/test_sleep.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/tests/test_sleep.rs:3 | assert_eq!(clock.now() - start, ms(5));
let mut e = task::spawn(sleep_until(&handle, clock.now() + ms(60)));
assert_pending!(poll!(e));
assert_ok!(driver.park());
assert_eq!(clock.now() - start, ms(64));
assert_pending!(poll!(e));
assert_ok!(driver.park());
assert_eq!(clock.now() - start... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_sleep.rs | MIT | ae67851f11b7cc1f577de8ce21767ce3e2c7aff9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ae67851f11b7cc1f577de8ce21767ce3e2c7aff9/tokio/src/time/tests/test_sleep.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/tests/test_sleep.rs:4 | assert_eq!(clock.now() - start, ms(65));
assert_ready_ok!(poll!(e1));
}
#[test]
fn sleep_with_deadline_in_past() {
let (mut driver, clock, handle) = setup();
let start = clock.now();
// Create `Sleep` that elapsed immediately.
let mut e = task::spawn(sleep_until(&handle, clock.now() - ms(100)));
... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_sleep.rs | MIT | ae67851f11b7cc1f577de8ce21767ce3e2c7aff9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ae67851f11b7cc1f577de8ce21767ce3e2c7aff9/tokio/src/time/tests/test_sleep.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/tests/test_sleep.rs:5 | assert_pending!(poll!(e));
// Turn the timer again
assert_ok!(driver.park_timeout(ms(1000)));
assert_eq!(clock.now() - start, ms(234));
// The sleep has elapsed.
assert_ready_ok!(poll!(e));
let (mut driver, clock, handle) = setup();
let start = clock.now();
// Create a `Sleep` that e... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_sleep.rs | MIT | ae67851f11b7cc1f577de8ce21767ce3e2c7aff9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ae67851f11b7cc1f577de8ce21767ce3e2c7aff9/tokio/src/time/tests/test_sleep.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/time/tests/test_sleep.rs:6 | fn concurrently_set_two_timers_second_one_shorter() {
let (mut driver, clock, handle) = setup();
let start = clock.now();
let mut e1 = task::spawn(sleep_until(&handle, clock.now() + ms(500)));
let mut e2 = task::spawn(sleep_until(&handle, clock.now() + ms(200)));
// The sleep has not elapsed
a... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_sleep.rs | MIT | ae67851f11b7cc1f577de8ce21767ce3e2c7aff9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ae67851f11b7cc1f577de8ce21767ce3e2c7aff9/tokio/src/time/tests/test_sleep.rs | 201 | 260 |
tokio-rs/tokio:tokio/src/time/tests/test_sleep.rs:7 | // Create a `Sleep` that elapses in the future
let mut e = task::spawn(sleep_until(&handle, clock.now() + ms(1)));
// The sleep has not elapsed.
assert_pending!(poll!(e));
// Turn the timer, but not enough time will go by.
assert_ok!(driver.park());
// The sleep has elapsed.
assert_ready_... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_sleep.rs | MIT | ae67851f11b7cc1f577de8ce21767ce3e2c7aff9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ae67851f11b7cc1f577de8ce21767ce3e2c7aff9/tokio/src/time/tests/test_sleep.rs | 241 | 300 |
tokio-rs/tokio:tokio/src/time/tests/test_sleep.rs:8 | // The sleep has elapsed.
assert_ready_ok!(poll!(e));
}
#[test]
fn very_long_sleep() {
const MO_5: u64 = 5 * 30 * 24 * 60 * 60 * 1000;
let (mut driver, clock, handle) = setup();
let start = clock.now();
// Create a `Sleep` that elapses in the future
let mut e = task::spawn(sleep_until(&handle... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_sleep.rs | MIT | ae67851f11b7cc1f577de8ce21767ce3e2c7aff9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ae67851f11b7cc1f577de8ce21767ce3e2c7aff9/tokio/src/time/tests/test_sleep.rs | 281 | 340 |
tokio-rs/tokio:tokio/src/time/tests/test_sleep.rs:9 | }
#[test]
fn unpark_is_delayed() {
// A special park that will take much longer than the requested duration
struct MockPark(Clock);
struct MockUnpark;
impl Park for MockPark {
type Unpark = MockUnpark;
type Error = ();
fn unpark(&self) -> Self::Unpark {
MockUnpark... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_sleep.rs | MIT | ae67851f11b7cc1f577de8ce21767ce3e2c7aff9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ae67851f11b7cc1f577de8ce21767ce3e2c7aff9/tokio/src/time/tests/test_sleep.rs | 321 | 380 |
tokio-rs/tokio:tokio/src/time/tests/test_sleep.rs:10 | let mut e1 = task::spawn(sleep_until(&handle, clock.now() + ms(100)));
let mut e2 = task::spawn(sleep_until(&handle, clock.now() + ms(101)));
let mut e3 = task::spawn(sleep_until(&handle, clock.now() + ms(200)));
assert_pending!(poll!(e1));
assert_pending!(poll!(e2));
assert_pending!(poll!(e3));
... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_sleep.rs | MIT | ae67851f11b7cc1f577de8ce21767ce3e2c7aff9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ae67851f11b7cc1f577de8ce21767ce3e2c7aff9/tokio/src/time/tests/test_sleep.rs | 361 | 420 |
tokio-rs/tokio:tokio/src/time/tests/test_sleep.rs:11 | clock.pause();
let driver = Driver::new(MockPark(clock.clone()), clock.clone());
let handle = driver.handle();
(driver, clock, handle)
}
fn sleep_until(handle: &Handle, when: Instant) -> Arc<Entry> {
Entry::new(&handle, when, ms(0))
}
struct MockPark(Clock);
struct MockUnpark;
impl Park for MockPar... | rust | rust | testsuite | tokio-rs/tokio | tokio/src/time/tests/test_sleep.rs | MIT | ae67851f11b7cc1f577de8ce21767ce3e2c7aff9 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ae67851f11b7cc1f577de8ce21767ce3e2c7aff9/tokio/src/time/tests/test_sleep.rs | 401 | 443 |
tokio-rs/tokio:tokio/src/time/throttle.rs:1 | //! Slow down a stream by enforcing a delay between items.
use crate::stream::Stream;
use crate::time::{Delay, Duration, Instant};
use std::future::Future;
use std::marker::Unpin;
use std::pin::Pin;
use std::task::{self, Poll};
use pin_project_lite::pin_project;
/// Slows down a stream by enforcing a delay between ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/throttle.rs | MIT | a32f918671ef641affbfcc4d4005ab738da795df | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a32f918671ef641affbfcc4d4005ab738da795df/tokio/src/time/throttle.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/throttle.rs:2 | };
Throttle {
delay,
duration,
has_delayed: true,
stream,
}
}
pin_project! {
/// Stream for the [`throttle`](throttle) function.
#[derive(Debug)]
#[must_use = "streams do nothing unless polled"]
pub struct Throttle<T> {
// `None` when duration is zero.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/throttle.rs | MIT | a32f918671ef641affbfcc4d4005ab738da795df | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a32f918671ef641affbfcc4d4005ab738da795df/tokio/src/time/throttle.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/throttle.rs:3 | /// which may otherwise confuse this combinator.
pub fn get_mut(&mut self) -> &mut T {
&mut self.stream
}
/// Consumes this combinator, returning the underlying stream.
///
/// Note that this may discard intermediate state of this combinator, so care
/// should be taken to avoid losing ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/throttle.rs | MIT | a32f918671ef641affbfcc4d4005ab738da795df | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a32f918671ef641affbfcc4d4005ab738da795df/tokio/src/time/throttle.rs | 81 | 117 |
tokio-rs/tokio:tokio/src/time/throttle.rs:1 | //! Slow down a stream by enforcing a delay between items.
use crate::stream::Stream;
use crate::time::{Delay, Duration, Instant};
use std::future::Future;
use std::marker::Unpin;
use std::pin::Pin;
use std::task::{self, Poll};
use pin_project_lite::pin_project;
/// Slows down a stream by enforcing a delay between ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/throttle.rs | MIT | f9ddb93604a830d106475bd4c4cae436fafcc0da | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f9ddb93604a830d106475bd4c4cae436fafcc0da/tokio/src/time/throttle.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/throttle.rs:1 | //! Slow down a stream by enforcing a delay between items.
use crate::stream::Stream;
use crate::time::{Delay, Duration, Instant};
use std::future::Future;
use std::marker::Unpin;
use std::pin::Pin;
use std::task::{self, Poll};
use pin_project_lite::pin_project;
/// Slow down a stream by enforcing a delay between i... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/throttle.rs | MIT | 8656b7b8eb6f3635ec40694eb71f14fb84211e05 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8656b7b8eb6f3635ec40694eb71f14fb84211e05/tokio/src/time/throttle.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/throttle.rs:2 | };
Throttle {
delay,
duration,
has_delayed: true,
stream,
}
}
pin_project! {
/// Stream for the [`throttle`](throttle) function.
#[derive(Debug)]
#[must_use = "streams do nothing unless polled"]
pub struct Throttle<T> {
// `None` when duration is zero.
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/throttle.rs | MIT | 4c645866ef4ea5b0ef8c7852281a09b2f96d969b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4c645866ef4ea5b0ef8c7852281a09b2f96d969b/tokio/src/time/throttle.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/throttle.rs:3 | /// which may otherwise confuse this combinator.
pub fn get_mut(&mut self) -> &mut T {
&mut self.stream
}
/// Consumes this combinator, returning the underlying stream.
///
/// Note that this may discard intermediate state of this combinator, so care
/// should be taken to avoid losing ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/throttle.rs | MIT | 4c645866ef4ea5b0ef8c7852281a09b2f96d969b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4c645866ef4ea5b0ef8c7852281a09b2f96d969b/tokio/src/time/throttle.rs | 81 | 122 |
tokio-rs/tokio:tokio/src/time/throttle.rs:1 | //! Slow down a stream by enforcing a delay between items.
use crate::time::{Delay, Duration, Instant};
use std::future::Future;
use std::marker::Unpin;
use std::pin::Pin;
use std::task::{self, Poll};
use futures_core::Stream;
use pin_project_lite::pin_project;
/// Slow down a stream by enforcing a delay between it... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/throttle.rs | MIT | 4b85565bd7ad973cd990977ed251d3cecfb50d0b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/4b85565bd7ad973cd990977ed251d3cecfb50d0b/tokio/src/time/throttle.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/throttle.rs:1 | //! Slow down a stream by enforcing a delay between items.
use crate::time::{Delay, Duration, Instant};
use std::future::Future;
use std::marker::Unpin;
use std::pin::Pin;
use std::task::{self, Poll};
/// Slow down a stream by enforcing a delay between items.
#[derive(Debug)]
#[must_use = "streams do nothing unless ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/throttle.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/throttle.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/throttle.rs:2 | // XXX: are these safe if `T: !Unpin`?
impl<T: Unpin> Throttle<T> {
/// Acquires a reference to the underlying stream that this combinator is
/// pulling from.
pub fn get_ref(&self) -> &T {
&self.stream
}
/// Acquires a mutable reference to the underlying stream that this combinator
///... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/throttle.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/throttle.rs | 41 | 96 |
tokio-rs/tokio:tokio/src/time/throttle.rs:3 | .as_mut()
.map_unchecked_mut(|me| &mut me.stream)
.poll_next(cx));
if value.is_some() {
if let Some(ref mut delay) = self.as_mut().get_unchecked_mut().delay {
delay.reset_timeout();
}
self.as_mut().get_unch... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/throttle.rs | MIT | 8a7e57786a5dca139f5b4261685e22991ded0859 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8a7e57786a5dca139f5b4261685e22991ded0859/tokio/src/time/throttle.rs | 81 | 96 |
tokio-rs/tokio:tokio/src/time/throttle.rs:1 | //! Slow down a stream by enforcing a delay between items.
use crate::time::{Delay, Instant};
use futures_core::ready;
use futures_core::Stream;
use std::{
future::Future,
marker::Unpin,
pin::Pin,
task::{self, Poll},
time::Duration,
};
/// Slow down a stream by enforcing a delay between items.
#[... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/throttle.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/time/throttle.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/throttle.rs:2 | stream,
}
}
}
// XXX: are these safe if `T: !Unpin`?
impl<T: Unpin> Throttle<T> {
/// Acquires a reference to the underlying stream that this combinator is
/// pulling from.
pub fn get_ref(&self) -> &T {
&self.stream
}
/// Acquires a mutable reference to the underlying stream t... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/throttle.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/time/throttle.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/throttle.rs:3 | .poll(cx));
self.as_mut().get_unchecked_mut().has_delayed = true;
}
let value = ready!(self
.as_mut()
.map_unchecked_mut(|me| &mut me.stream)
.poll_next(cx));
if value.is_some() {
if let Some(ref mut de... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/throttle.rs | MIT | 27e5b41067d01c0c9fac230c5addb58034201a63 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/27e5b41067d01c0c9fac230c5addb58034201a63/tokio/src/time/throttle.rs | 81 | 101 |
tokio-rs/tokio:tokio/src/time/timeout.rs:4 | /// The original future may be obtained by calling [`Timeout::into_inner`]. This
/// consumes the `Timeout`.
///
/// # Examples
///
/// Create a new `Timeout` set to expire in 10 milliseconds.
///
/// ```rust
/// use tokio::time::{Instant, timeout_at};
/// use tokio::sync::oneshot;
///
/// use std::time::Duration;
///
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/time/timeout.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/timeout.rs:5 | /// [`Builder::enable_time`]: crate::runtime::Builder::enable_time
/// [`Builder::enable_all`]: crate::runtime::Builder::enable_all
#[track_caller]
pub fn timeout_at<F>(deadline: Instant, future: F) -> Timeout<F::IntoFuture>
where
F: IntoFuture,
{
let delay = sleep_until(deadline);
Timeout::new_with_delay(f... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/time/timeout.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/time/timeout.rs:6 | self.value
}
}
impl<T> Future for Timeout<T>
where
T: Future,
{
type Output = Result<T::Output, Elapsed>;
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
let me = self.project();
let had_budget_before = coop::has_budget_remaining();
// First,... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/c6d58ce7e7bf4a6e7e6efc1ffeb42daa3a627c17/tokio/src/time/timeout.rs | 201 | 249 |
tokio-rs/tokio:tokio/src/time/timeout.rs:4 | /// The original future may be obtained by calling [`Timeout::into_inner`]. This
/// consumes the `Timeout`.
///
/// # Examples
///
/// Create a new `Timeout` set to expire in 10 milliseconds.
///
/// ```rust
/// use tokio::time::{Instant, timeout_at};
/// use tokio::sync::oneshot;
///
/// use std::time::Duration;
///
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | 925c614c89d0a26777a334612e2ed6ad0e7935c3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/925c614c89d0a26777a334612e2ed6ad0e7935c3/tokio/src/time/timeout.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/timeout.rs:5 | pub struct Timeout<T> {
#[pin]
value: T,
#[pin]
delay: Sleep,
}
}
impl<T> Timeout<T> {
pub(crate) fn new_with_delay(value: T, delay: Sleep) -> Timeout<T> {
Timeout { value, delay }
}
/// Gets a reference to the underlying value in this timeout.
pub fn get_re... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | 925c614c89d0a26777a334612e2ed6ad0e7935c3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/925c614c89d0a26777a334612e2ed6ad0e7935c3/tokio/src/time/timeout.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/time/timeout.rs:6 | // First, try polling the future
if let Poll::Ready(v) = me.value.poll(cx) {
return Poll::Ready(Ok(v));
}
poll_delay(had_budget_before, me.delay, cx).map(Err)
}
}
// The T-invariant portion of Timeout::<T>::poll. Pulling this out reduces the
// amount of code that gets duplicat... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | 925c614c89d0a26777a334612e2ed6ad0e7935c3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/925c614c89d0a26777a334612e2ed6ad0e7935c3/tokio/src/time/timeout.rs | 201 | 234 |
tokio-rs/tokio:tokio/src/time/timeout.rs:5 | pub struct Timeout<T> {
#[pin]
value: T,
#[pin]
delay: Sleep,
}
}
impl<T> Timeout<T> {
pub(crate) fn new_with_delay(value: T, delay: Sleep) -> Timeout<T> {
Timeout { value, delay }
}
/// Gets a reference to the underlying value in this timeout.
pub fn get_re... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | 605ef578df04f12a951060dc3b2fb930f6f379fe | github | async-runtime | https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/time/timeout.rs | 161 | 220 |
tokio-rs/tokio:tokio/src/time/timeout.rs:6 | // First, try polling the future
if let Poll::Ready(v) = me.value.poll(cx) {
return Poll::Ready(Ok(v));
}
let has_budget_now = coop::has_budget_remaining();
let delay = me.delay;
let poll_delay = || -> Poll<Self::Output> {
match delay.poll(cx) {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | 605ef578df04f12a951060dc3b2fb930f6f379fe | github | async-runtime | https://github.com/tokio-rs/tokio/blob/605ef578df04f12a951060dc3b2fb930f6f379fe/tokio/src/time/timeout.rs | 201 | 228 |
tokio-rs/tokio:tokio/src/time/timeout.rs:4 | /// The original future may be obtained by calling [`Timeout::into_inner`]. This
/// consumes the `Timeout`.
///
/// # Examples
///
/// Create a new `Timeout` set to expire in 10 milliseconds.
///
/// ```rust
/// use tokio::time::{Instant, timeout_at};
/// use tokio::sync::oneshot;
///
/// use std::time::Duration;
///
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | 8eb94a33c078831a4e0680bf59e6ea6aefa5d970 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/8eb94a33c078831a4e0680bf59e6ea6aefa5d970/tokio/src/time/timeout.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/timeout.rs:3 | pub fn timeout<F>(duration: Duration, future: F) -> Timeout<F>
where
F: Future,
{
let location = trace::caller_location();
let deadline = Instant::now().checked_add(duration);
let delay = match deadline {
Some(deadline) => Sleep::new_timeout(deadline, location),
None => Sleep::far_futur... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/time/timeout.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/timeout.rs:4 | ///
/// use std::time::Duration;
///
/// # async fn dox() {
/// let (tx, rx) = oneshot::channel();
/// # tx.send(()).unwrap();
///
/// // Wrap the future with a `Timeout` set to expire 10 milliseconds into the
/// // future.
/// if let Err(_) = timeout_at(Instant::now() + Duration::from_millis(10), rx).await {
/// ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/time/timeout.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/timeout.rs:5 | Timeout { value, delay }
}
/// Gets a reference to the underlying value in this timeout.
pub fn get_ref(&self) -> &T {
&self.value
}
/// Gets a mutable reference to the underlying value in this timeout.
pub fn get_mut(&mut self) -> &mut T {
&mut self.value
}
/// Consum... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/time/timeout.rs | 161 | 218 |
tokio-rs/tokio:tokio/src/time/timeout.rs:6 | match delay.poll(cx) {
Poll::Ready(()) => Poll::Ready(Err(Elapsed::new())),
Poll::Pending => Poll::Pending,
}
};
if let (true, false) = (had_budget_before, has_budget_now) {
// if it is the underlying future that exhausted the budget, we poll
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | a051ed726f3b99b077e8c9ef8ef1df2ab2943213 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/a051ed726f3b99b077e8c9ef8ef1df2ab2943213/tokio/src/time/timeout.rs | 201 | 218 |
tokio-rs/tokio:tokio/src/time/timeout.rs:3 | let location = trace::caller_location();
let deadline = Instant::now().checked_add(duration);
let delay = match deadline {
Some(deadline) => Sleep::new_timeout(deadline, location),
None => Sleep::far_future(location),
};
Timeout::new_with_delay(future, delay)
}
/// Requires a `Future` ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | d32ba2cf9d9b7eac3a904f558e5fe4397cc83e89 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d32ba2cf9d9b7eac3a904f558e5fe4397cc83e89/tokio/src/time/timeout.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/timeout.rs:4 | /// let (tx, rx) = oneshot::channel();
/// # tx.send(()).unwrap();
///
/// // Wrap the future with a `Timeout` set to expire 10 milliseconds into the
/// // future.
/// if let Err(_) = timeout_at(Instant::now() + Duration::from_millis(10), rx).await {
/// println!("did not receive value within 10 ms");
/// }
/// # ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | d32ba2cf9d9b7eac3a904f558e5fe4397cc83e89 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d32ba2cf9d9b7eac3a904f558e5fe4397cc83e89/tokio/src/time/timeout.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/timeout.rs:5 | pub fn get_ref(&self) -> &T {
&self.value
}
/// Gets a mutable reference to the underlying value in this timeout.
pub fn get_mut(&mut self) -> &mut T {
&mut self.value
}
/// Consumes this timeout, returning the underlying value.
pub fn into_inner(self) -> T {
self.value... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | d32ba2cf9d9b7eac3a904f558e5fe4397cc83e89 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d32ba2cf9d9b7eac3a904f558e5fe4397cc83e89/tokio/src/time/timeout.rs | 161 | 214 |
tokio-rs/tokio:tokio/src/time/timeout.rs:6 | };
if let (true, false) = (had_budget_before, has_budget_now) {
// if it is the underlying future that exhausted the budget, we poll
// the `delay` with an unconstrained one. This prevents pathological
// cases where the underlying future always exhausts the budget and
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | d32ba2cf9d9b7eac3a904f558e5fe4397cc83e89 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d32ba2cf9d9b7eac3a904f558e5fe4397cc83e89/tokio/src/time/timeout.rs | 201 | 214 |
tokio-rs/tokio:tokio/src/time/timeout.rs:3 | };
Timeout::new_with_delay(future, delay)
}
/// Requires a `Future` to complete before the specified instant in time.
///
/// If the future completes before the instant is reached, then the completed
/// value is returned. Otherwise, an error is returned.
///
/// # Cancellation
///
/// Cancelling a timeout is done... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | f26ce08f37d8c8426736412f7aca51f4f39d43d3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f26ce08f37d8c8426736412f7aca51f4f39d43d3/tokio/src/time/timeout.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/timeout.rs:4 | T: Future,
{
let delay = sleep_until(deadline);
Timeout {
value: future,
delay,
}
}
pin_project! {
/// Future returned by [`timeout`](timeout) and [`timeout_at`](timeout_at).
#[must_use = "futures do nothing unless you `.await` or poll them"]
#[derive(Debug)]
pub struct Tim... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | f26ce08f37d8c8426736412f7aca51f4f39d43d3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f26ce08f37d8c8426736412f7aca51f4f39d43d3/tokio/src/time/timeout.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/timeout.rs:5 | }
}
impl<T> Future for Timeout<T>
where
T: Future,
{
type Output = Result<T::Output, Elapsed>;
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
let me = self.project();
let had_budget_before = coop::has_budget_remaining();
// First, try polling th... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | f26ce08f37d8c8426736412f7aca51f4f39d43d3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/f26ce08f37d8c8426736412f7aca51f4f39d43d3/tokio/src/time/timeout.rs | 161 | 202 |
tokio-rs/tokio:tokio/src/time/timeout.rs:3 | };
Timeout::new_with_delay(future, delay)
}
/// Requires a `Future` to complete before the specified instant in time.
///
/// If the future completes before the instant is reached, then the completed
/// value is returned. Otherwise, an error is returned.
///
/// # Cancelation
///
/// Cancelling a timeout is done ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | 54e6693dff86e6e9d687ed3952bbc2c68bb6db8d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/54e6693dff86e6e9d687ed3952bbc2c68bb6db8d/tokio/src/time/timeout.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/timeout.rs:3 | Timeout::new_with_delay(future, delay)
}
/// Requires a `Future` to complete before the specified instant in time.
///
/// If the future completes before the instant is reached, then the completed
/// value is returned. Otherwise, an error is returned.
///
/// # Cancelation
///
/// Cancelling a timeout is done by drop... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | 2c0e5c97049cbd527754477709839fb1f52ed282 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2c0e5c97049cbd527754477709839fb1f52ed282/tokio/src/time/timeout.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/timeout.rs:4 | {
let delay = sleep_until(deadline);
Timeout {
value: future,
delay,
}
}
pin_project! {
/// Future returned by [`timeout`](timeout) and [`timeout_at`](timeout_at).
#[must_use = "futures do nothing unless you `.await` or poll them"]
#[derive(Debug)]
pub struct Timeout<T> {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | 2c0e5c97049cbd527754477709839fb1f52ed282 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2c0e5c97049cbd527754477709839fb1f52ed282/tokio/src/time/timeout.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/timeout.rs:5 | }
impl<T> Future for Timeout<T>
where
T: Future,
{
type Output = Result<T::Output, Elapsed>;
fn poll(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
let me = self.project();
// First, try polling the future
if let Poll::Ready(v) = me.value.poll(cx) {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | 2c0e5c97049cbd527754477709839fb1f52ed282 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/2c0e5c97049cbd527754477709839fb1f52ed282/tokio/src/time/timeout.rs | 161 | 183 |
tokio-rs/tokio:tokio/src/time/timeout.rs:1 | //! Allows a future to execute for a maximum amount of time.
//!
//! See [`Timeout`] documentation for more details.
//!
//! [`Timeout`]: struct@Timeout
use crate::{
time::{error::Elapsed, sleep_until, Duration, Instant, Sleep},
util::trace,
};
use pin_project_lite::pin_project;
use std::future::Future;
use s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | cf3206842c0d94ecdaaeb421a58b1c963b627c3d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cf3206842c0d94ecdaaeb421a58b1c963b627c3d/tokio/src/time/timeout.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/timeout.rs:2 | /// # async fn dox() {
/// let (tx, rx) = oneshot::channel();
/// # tx.send(()).unwrap();
///
/// // Wrap the future with a `Timeout` set to expire in 10 milliseconds.
/// if let Err(_) = timeout(Duration::from_millis(10), rx).await {
/// println!("did not receive value within 10 ms");
/// }
/// # }
/// ```
#[track... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | cf3206842c0d94ecdaaeb421a58b1c963b627c3d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cf3206842c0d94ecdaaeb421a58b1c963b627c3d/tokio/src/time/timeout.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/timeout.rs:3 | /// Create a new `Timeout` set to expire in 10 milliseconds.
///
/// ```rust
/// use tokio::time::{Instant, timeout_at};
/// use tokio::sync::oneshot;
///
/// use std::time::Duration;
///
/// # async fn dox() {
/// let (tx, rx) = oneshot::channel();
/// # tx.send(()).unwrap();
///
/// // Wrap the future with a `Timeout... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | cf3206842c0d94ecdaaeb421a58b1c963b627c3d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cf3206842c0d94ecdaaeb421a58b1c963b627c3d/tokio/src/time/timeout.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/timeout.rs:4 | }
}
impl<T> Timeout<T> {
pub(crate) fn new_with_delay(value: T, delay: Sleep) -> Timeout<T> {
Timeout { value, delay }
}
/// Gets a reference to the underlying value in this timeout.
pub fn get_ref(&self) -> &T {
&self.value
}
/// Gets a mutable reference to the underlying val... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | cf3206842c0d94ecdaaeb421a58b1c963b627c3d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/cf3206842c0d94ecdaaeb421a58b1c963b627c3d/tokio/src/time/timeout.rs | 121 | 165 |
tokio-rs/tokio:tokio/src/time/timeout.rs:1 | //! Allows a future to execute for a maximum amount of time.
//!
//! See [`Timeout`] documentation for more details.
//!
//! [`Timeout`]: struct@Timeout
use crate::{
time::{error::Elapsed, sleep_until, Duration, Instant, Sleep},
util::trace,
};
use pin_project_lite::pin_project;
use std::future::Future;
use s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/time/timeout.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/timeout.rs:2 | /// # async fn dox() {
/// let (tx, rx) = oneshot::channel();
/// # tx.send(()).unwrap();
///
/// // Wrap the future with a `Timeout` set to expire in 10 milliseconds.
/// if let Err(_) = timeout(Duration::from_millis(10), rx).await {
/// println!("did not receive value within 10 ms");
/// }
/// # }
/// ```
#[cfg_a... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | 03969cdae7674681d1b10926e6a56fbb8908dbb8 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/03969cdae7674681d1b10926e6a56fbb8908dbb8/tokio/src/time/timeout.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/timeout.rs:1 | //! Allows a future to execute for a maximum amount of time.
//!
//! See [`Timeout`] documentation for more details.
//!
//! [`Timeout`]: struct@Timeout
use crate::{
time::{error::Elapsed, sleep_until, Duration, Instant, Sleep},
util::trace,
};
use pin_project_lite::pin_project;
use std::future::Future;
use s... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | b9834f6d8b3563e6907456d19fe418cfe19983c3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b9834f6d8b3563e6907456d19fe418cfe19983c3/tokio/src/time/timeout.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/timeout.rs:2 | /// # async fn dox() {
/// let (tx, rx) = oneshot::channel();
/// # tx.send(()).unwrap();
///
/// // Wrap the future with a `Timeout` set to expire in 10 milliseconds.
/// if let Err(_) = timeout(Duration::from_millis(10), rx).await {
/// println!("did not receive value within 10 ms");
/// }
/// # }
/// ```
#[cfg_a... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | b9834f6d8b3563e6907456d19fe418cfe19983c3 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/b9834f6d8b3563e6907456d19fe418cfe19983c3/tokio/src/time/timeout.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/timeout.rs:1 | //! Allows a future to execute for a maximum amount of time.
//!
//! See [`Timeout`] documentation for more details.
//!
//! [`Timeout`]: struct@Timeout
use crate::time::{error::Elapsed, sleep_until, Duration, Instant, Sleep};
use pin_project_lite::pin_project;
use std::future::Future;
use std::pin::Pin;
use std::tas... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | d2ad7afd21e4faef05ccccb0288bc814a954b990 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d2ad7afd21e4faef05ccccb0288bc814a954b990/tokio/src/time/timeout.rs | 1 | 60 |
tokio-rs/tokio:tokio/src/time/timeout.rs:2 | ///
/// // Wrap the future with a `Timeout` set to expire in 10 milliseconds.
/// if let Err(_) = timeout(Duration::from_millis(10), rx).await {
/// println!("did not receive value within 10 ms");
/// }
/// # }
/// ```
pub fn timeout<T>(duration: Duration, future: T) -> Timeout<T>
where
T: Future,
{
let dea... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | d2ad7afd21e4faef05ccccb0288bc814a954b990 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d2ad7afd21e4faef05ccccb0288bc814a954b990/tokio/src/time/timeout.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/timeout.rs:3 | /// use std::time::Duration;
///
/// # async fn dox() {
/// let (tx, rx) = oneshot::channel();
/// # tx.send(()).unwrap();
///
/// // Wrap the future with a `Timeout` set to expire 10 milliseconds into the
/// // future.
/// if let Err(_) = timeout_at(Instant::now() + Duration::from_millis(10), rx).await {
/// prin... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | d2ad7afd21e4faef05ccccb0288bc814a954b990 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d2ad7afd21e4faef05ccccb0288bc814a954b990/tokio/src/time/timeout.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/timeout.rs:4 | }
/// Gets a reference to the underlying value in this timeout.
pub fn get_ref(&self) -> &T {
&self.value
}
/// Gets a mutable reference to the underlying value in this timeout.
pub fn get_mut(&mut self) -> &mut T {
&mut self.value
}
/// Consumes this timeout, returning th... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | d2ad7afd21e4faef05ccccb0288bc814a954b990 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/d2ad7afd21e4faef05ccccb0288bc814a954b990/tokio/src/time/timeout.rs | 121 | 159 |
tokio-rs/tokio:tokio/src/time/timeout.rs:2 | ///
/// // Wrap the future with a `Timeout` set to expire in 10 milliseconds.
/// if let Err(_) = timeout(Duration::from_millis(10), rx).await {
/// println!("did not receive value within 10 ms");
/// }
/// # }
/// ```
pub fn timeout<T>(duration: Duration, future: T) -> Timeout<T>
where
T: Future,
{
let del... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | ce0e9c67cfe61c7a91a284331ecc53fa01c32879 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ce0e9c67cfe61c7a91a284331ecc53fa01c32879/tokio/src/time/timeout.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/timeout.rs:3 | /// # tx.send(()).unwrap();
///
/// // Wrap the future with a `Timeout` set to expire 10 milliseconds into the
/// // future.
/// if let Err(_) = timeout_at(Instant::now() + Duration::from_millis(10), rx).await {
/// println!("did not receive value within 10 ms");
/// }
/// # }
/// ```
pub fn timeout_at<T>(deadline... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | ce0e9c67cfe61c7a91a284331ecc53fa01c32879 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ce0e9c67cfe61c7a91a284331ecc53fa01c32879/tokio/src/time/timeout.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/timeout.rs:4 | &self.value
}
/// Gets a mutable reference to the underlying value in this timeout.
pub fn get_mut(&mut self) -> &mut T {
&mut self.value
}
/// Consumes this timeout, returning the underlying value.
pub fn into_inner(self) -> T {
self.value
}
}
impl<T> Future for Timeout<T... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | ce0e9c67cfe61c7a91a284331ecc53fa01c32879 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/ce0e9c67cfe61c7a91a284331ecc53fa01c32879/tokio/src/time/timeout.rs | 121 | 155 |
tokio-rs/tokio:tokio/src/time/timeout.rs:4 | &self.value
}
/// Gets a mutable reference to the underlying value in this timeout.
pub fn get_mut(&mut self) -> &mut T {
&mut self.value
}
/// Consumes this timeout, returning the underlying value.
pub fn into_inner(self) -> T {
self.value
}
}
impl<T> Future for Timeout<T... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | 575938d4579e6fe6a89b700aadb0ae2bbab5483b | github | async-runtime | https://github.com/tokio-rs/tokio/blob/575938d4579e6fe6a89b700aadb0ae2bbab5483b/tokio/src/time/timeout.rs | 121 | 155 |
tokio-rs/tokio:tokio/src/time/timeout.rs:2 | ///
/// // Wrap the future with a `Timeout` set to expire in 10 milliseconds.
/// if let Err(_) = timeout(Duration::from_millis(10), rx).await {
/// println!("did not receive value within 10 ms");
/// }
/// # }
/// ```
pub fn timeout<T>(duration: Duration, future: T) -> Timeout<T>
where
T: Future,
{
let del... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | 0893841f31542b2b04c5050a8a4a3c45cf867e55 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/0893841f31542b2b04c5050a8a4a3c45cf867e55/tokio/src/time/timeout.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/timeout.rs:2 | /// # tx.send(()).unwrap();
///
/// // Wrap the future with a `Timeout` set to expire in 10 milliseconds.
/// if let Err(_) = timeout(Duration::from_millis(10), rx).await {
/// println!("did not receive value within 10 ms");
/// }
/// # }
/// ```
pub fn timeout<T>(duration: Duration, future: T) -> Timeout<T>
where
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | 60d81bbe10faf344ea18438a1c5ecb9173e6ec52 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/60d81bbe10faf344ea18438a1c5ecb9173e6ec52/tokio/src/time/timeout.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/timeout.rs:3 | /// let (tx, rx) = oneshot::channel();
/// # tx.send(()).unwrap();
///
/// // Wrap the future with a `Timeout` set to expire 10 milliseconds into the
/// // future.
/// if let Err(_) = timeout_at(Instant::now() + Duration::from_millis(10), rx).await {
/// println!("did not receive value within 10 ms");
/// }
/// # ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | 60d81bbe10faf344ea18438a1c5ecb9173e6ec52 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/60d81bbe10faf344ea18438a1c5ecb9173e6ec52/tokio/src/time/timeout.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/timeout.rs:4 | #[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 }
}
/// Gets a reference to the underlying value in this timeout.
pub fn get_ref(&self) -> &T {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | 60d81bbe10faf344ea18438a1c5ecb9173e6ec52 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/60d81bbe10faf344ea18438a1c5ecb9173e6ec52/tokio/src/time/timeout.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/timeout.rs:5 | // Now check the timer
match me.delay.poll(cx) {
Poll::Ready(()) => Poll::Ready(Err(Elapsed(()))),
Poll::Pending => Poll::Pending,
}
}
}
// ===== impl Elapsed =====
impl fmt::Display for Elapsed {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
"dea... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | 60d81bbe10faf344ea18438a1c5ecb9173e6ec52 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/60d81bbe10faf344ea18438a1c5ecb9173e6ec52/tokio/src/time/timeout.rs | 161 | 184 |
tokio-rs/tokio:tokio/src/time/timeout.rs:2 | /// # tx.send(()).unwrap();
///
/// // Wrap the future with a `Timeout` set to expire in 10 milliseconds.
/// if let Err(_) = timeout(Duration::from_millis(10), rx).await {
/// println!("did not receive value within 10 ms");
/// }
/// # }
/// ```
pub fn timeout<T>(duration: Duration, future: T) -> Timeout<T>
where
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | 53ccfc1fd694ee70c7a4d1e7af09a856bafb49e5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/53ccfc1fd694ee70c7a4d1e7af09a856bafb49e5/tokio/src/time/timeout.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/timeout.rs:3 | /// let (tx, rx) = oneshot::channel();
/// # tx.send(()).unwrap();
///
/// // Wrap the future with a `Timeout` set to expire 10 milliseconds into the
/// // future.
/// if let Err(_) = timeout_at(Instant::now() + Duration::from_millis(10), rx).await {
/// println!("did not receive value within 10 ms");
/// }
/// # ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | 53ccfc1fd694ee70c7a4d1e7af09a856bafb49e5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/53ccfc1fd694ee70c7a4d1e7af09a856bafb49e5/tokio/src/time/timeout.rs | 81 | 140 |
tokio-rs/tokio:tokio/src/time/timeout.rs:4 | #[allow(unused)]
pub(crate) fn new() -> Self {
Elapsed(())
}
}
impl<T> Timeout<T> {
pub(crate) fn new_with_delay(value: T, delay: Delay) -> Timeout<T> {
Timeout { value, delay }
}
/// Gets a reference to the underlying value in this timeout.
pub fn get_ref(&self) -> &T {
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | 53ccfc1fd694ee70c7a4d1e7af09a856bafb49e5 | github | async-runtime | https://github.com/tokio-rs/tokio/blob/53ccfc1fd694ee70c7a4d1e7af09a856bafb49e5/tokio/src/time/timeout.rs | 121 | 180 |
tokio-rs/tokio:tokio/src/time/timeout.rs:2 | /// # tx.send(()).unwrap();
///
/// // Wrap the future with a `Timeout` set to expire in 10 milliseconds.
/// if let Err(_) = timeout(Duration::from_millis(10), rx).await {
/// println!("did not receive value within 10 ms");
/// }
/// # }
/// ```
pub fn timeout<T>(duration: Duration, future: T) -> Timeout<T>
where
... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | 6b6e76080afc92450238df69c4edc12ee5f7518d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6b6e76080afc92450238df69c4edc12ee5f7518d/tokio/src/time/timeout.rs | 41 | 100 |
tokio-rs/tokio:tokio/src/time/timeout.rs:3 | /// let (tx, rx) = oneshot::channel();
/// # tx.send(()).unwrap();
///
/// // Wrap the future with a `Timeout` set to expire 10 milliseconds into the
/// // future.
/// if let Err(_) = timeout_at(Instant::now() + Duration::from_millis(10), rx).await {
/// println!("did not receive value within 10 ms");
/// }
/// # ... | rust | rust | rust-source | tokio-rs/tokio | tokio/src/time/timeout.rs | MIT | 6b6e76080afc92450238df69c4edc12ee5f7518d | github | async-runtime | https://github.com/tokio-rs/tokio/blob/6b6e76080afc92450238df69c4edc12ee5f7518d/tokio/src/time/timeout.rs | 81 | 140 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.