Skip to content

refactor: Rename delay_util to delay_until in MakeDelay trait #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fastimer-driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl MakeFastimerDelay {
impl MakeDelay for MakeFastimerDelay {
type Delay = Delay;

fn delay_util(&self, at: Instant) -> Self::Delay {
fn delay_until(&self, at: Instant) -> Self::Delay {
self.0.delay_until(at)
}

Expand Down
2 changes: 1 addition & 1 deletion fastimer-driver/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use fastimer_driver::binary_heap_driver;
#[track_caller]
fn assert_duration_eq(actual: Duration, expected: Duration) {
if expected.abs_diff(actual) > Duration::from_millis(250) {
panic!("expected: {:?}, actual: {:?}", expected, actual);
panic!("expected: {expected:?}, actual: {actual:?}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion fastimer-tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mod delay {
impl MakeDelay for MakeTokioDelay {
type Delay = tokio::time::Sleep;

fn delay_util(&self, at: Instant) -> Self::Delay {
fn delay_until(&self, at: Instant) -> Self::Delay {
tokio::time::sleep_until(tokio::time::Instant::from_std(at))
}

Expand Down
10 changes: 5 additions & 5 deletions fastimer/src/interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use crate::far_future;
/// struct TokioDelay;
/// impl MakeDelay for TokioDelay {
/// type Delay = tokio::time::Sleep;
/// fn delay_util(&self, until: Instant) -> Self::Delay {
/// fn delay_until(&self, until: Instant) -> Self::Delay {
/// tokio::time::sleep_until(tokio::time::Instant::from_std(until))
/// }
/// }
Expand Down Expand Up @@ -91,7 +91,7 @@ use crate::far_future;
/// struct TokioDelay;
/// impl MakeDelay for TokioDelay {
/// type Delay = tokio::time::Sleep;
/// fn delay_util(&self, until: Instant) -> Self::Delay {
/// fn delay_until(&self, until: Instant) -> Self::Delay {
/// tokio::time::sleep_until(tokio::time::Instant::from_std(until))
/// }
/// }
Expand Down Expand Up @@ -145,7 +145,7 @@ pub fn interval<D: MakeDelay>(period: Duration, make_delay: D) -> Interval<D> {
/// struct TokioDelay;
/// impl MakeDelay for TokioDelay {
/// type Delay = tokio::time::Sleep;
/// fn delay_util(&self, until: Instant) -> Self::Delay {
/// fn delay_until(&self, until: Instant) -> Self::Delay {
/// tokio::time::sleep_until(tokio::time::Instant::from_std(until))
/// }
/// }
Expand All @@ -168,7 +168,7 @@ pub fn interval_at<D: MakeDelay>(start: Instant, period: Duration, make_delay: D

fn make_interval<D: MakeDelay>(start: Instant, period: Duration, make_delay: D) -> Interval<D> {
let deadline = start;
let delay = Box::pin(make_delay.delay_util(start));
let delay = Box::pin(make_delay.delay_until(start));
Interval {
deadline,
period,
Expand Down Expand Up @@ -267,7 +267,7 @@ impl<D: MakeDelay> Interval<D> {
// When we arrive here, the internal delay returned `Poll::Ready`.
// Reassign the delay but do not register it. It should be registered with
// the next call to `poll_tick`.
self.delay = Box::pin(self.make_delay.delay_util(next));
self.delay = Box::pin(self.make_delay.delay_until(next));

// Return the time when we were scheduled to tick
self.deadline = next;
Expand Down
4 changes: 2 additions & 2 deletions fastimer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ pub trait MakeDelay {
type Delay: Future<Output = ()> + Send;

/// Create a future that completes at the specified instant.
fn delay_util(&self, at: Instant) -> Self::Delay;
fn delay_until(&self, at: Instant) -> Self::Delay;

/// Create a future that completes after the specified duration.
fn delay(&self, duration: Duration) -> Self::Delay {
self.delay_util(make_instant_from_now(duration))
self.delay_until(make_instant_from_now(duration))
}
}

Expand Down
2 changes: 1 addition & 1 deletion fastimer/src/schedule/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub trait ArbitraryDelayActionExt: ArbitraryDelayAction {
ControlFlow::Break(()) => break,
};

if execute_or_shutdown(make_delay.delay_util(next), &mut is_shutdown)
if execute_or_shutdown(make_delay.delay_until(next), &mut is_shutdown)
.await
.is_break()
{
Expand Down
4 changes: 2 additions & 2 deletions fastimer/src/schedule/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pub trait SimpleActionExt: SimpleAction {
if let Some(initial_delay) = initial_delay {
if initial_delay > Duration::ZERO {
next = make_instant_from_now(initial_delay);
if execute_or_shutdown(make_delay.delay_util(next), &mut is_shutdown)
if execute_or_shutdown(make_delay.delay_until(next), &mut is_shutdown)
.await
.is_break()
{
Expand All @@ -185,7 +185,7 @@ pub trait SimpleActionExt: SimpleAction {
};

next = calculate_next_on_miss(next, period);
if execute_or_shutdown(make_delay.delay_util(next), &mut is_shutdown)
if execute_or_shutdown(make_delay.delay_until(next), &mut is_shutdown)
.await
.is_break()
{
Expand Down
2 changes: 1 addition & 1 deletion fastimer/src/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ where
F: IntoFuture,
D: MakeDelay + ?Sized,
{
let delay = make_delay.delay_util(deadline);
let delay = make_delay.delay_until(deadline);
Timeout {
value: future.into_future(),
delay,
Expand Down
2 changes: 1 addition & 1 deletion fastimer/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct MakeTokioDelay;
impl MakeDelay for MakeTokioDelay {
type Delay = tokio::time::Sleep;

fn delay_util(&self, at: Instant) -> Self::Delay {
fn delay_until(&self, at: Instant) -> Self::Delay {
tokio::time::sleep_until(tokio::time::Instant::from_std(at))
}

Expand Down
2 changes: 1 addition & 1 deletion fastimer/tests/interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mod common;
#[track_caller]
fn assert_duration_eq(actual: Duration, expected: Duration) {
if expected.abs_diff(actual) > Duration::from_millis(250) {
panic!("expected: {:?}, actual: {:?}", expected, actual);
panic!("expected: {expected:?}, actual: {actual:?}");
}
}

Expand Down
6 changes: 3 additions & 3 deletions fastimer/tests/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@ async fn test_simple_action() {
let shutdown = Instant::now() + Duration::from_secs(10);

MySimpleAction::new("schedule_with_fixed_delay").schedule_with_fixed_delay(
MakeTokioDelay.delay_util(shutdown),
MakeTokioDelay.delay_until(shutdown),
&TokioSpawn,
MakeTokioDelay,
initial_delay,
Duration::from_secs(2),
);

MySimpleAction::new("schedule_at_fixed_rate").schedule_at_fixed_rate(
MakeTokioDelay.delay_util(shutdown),
MakeTokioDelay.delay_until(shutdown),
&TokioSpawn,
MakeTokioDelay,
initial_delay,
Duration::from_secs(2),
);

MakeTokioDelay
.delay_util(shutdown + Duration::from_secs(1))
.delay_until(shutdown + Duration::from_secs(1))
.await;
}