Skip to content

Commit

Permalink
Add test of Timer using &mut RT
Browse files Browse the repository at this point in the history
To showcase that it's possible to avoid the cloning of RT.
  • Loading branch information
Thomasdezeeuw committed Dec 31, 2023
1 parent 96f377b commit 92c4931
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions rt/tests/functional/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,25 @@ fn timer() {
block_on_local_actor(actor_fn(actor), ()).unwrap();
}

#[test]
fn timer_ref_rt() {
async fn actor(mut ctx: actor::Context<!, ThreadLocal>) {
let start = Instant::now();
// Instead of cloning `ThreadLocal`, we can use a mutable reference to
// it.
let mut timer = Timer::after(ctx.runtime(), TIMEOUT);
assert!(timer.deadline() >= start + TIMEOUT);
assert!(!timer.has_passed());

let _ = (&mut timer).await;
assert!(timer.deadline() >= start + TIMEOUT);
assert!(timer.has_passed());
assert!(start.elapsed() >= TIMEOUT);
}

block_on_local_actor(actor_fn(actor), ()).unwrap();
}

#[derive(Clone, Debug, Eq, PartialEq)]
struct AlwaysPending;

Expand Down

0 comments on commit 92c4931

Please sign in to comment.