Skip to content

Commit 4be913b

Browse files
committed
tidy
Signed-off-by: tison <[email protected]>
1 parent f869ae9 commit 4be913b

File tree

4 files changed

+21
-35
lines changed

4 files changed

+21
-35
lines changed

fastimer/src/schedule/arbitrary.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use crate::info;
2222
use crate::schedule::BaseAction;
2323
use crate::schedule::delay_or_shutdown;
2424
use crate::schedule::execute_or_shutdown;
25-
use crate::schedule::initial_delay_or_shutdown;
2625

2726
/// Repeatable action that can be scheduled with arbitrary delay.
2827
///
@@ -54,8 +53,12 @@ pub trait ArbitraryDelayActionExt: ArbitraryDelayAction {
5453
);
5554

5655
'schedule: {
57-
if initial_delay_or_shutdown(&self, &make_delay, initial_delay).await {
58-
break 'schedule;
56+
if let Some(initial_delay) = initial_delay {
57+
if initial_delay > Duration::ZERO
58+
&& delay_or_shutdown(&mut self, make_delay.delay(initial_delay)).await
59+
{
60+
break 'schedule;
61+
}
5962
}
6063

6164
loop {
@@ -66,7 +69,7 @@ pub trait ArbitraryDelayActionExt: ArbitraryDelayAction {
6669
}
6770

6871
let next = self.next_run_at();
69-
if delay_or_shutdown(&self, make_delay.delay_util(next)).await {
72+
if delay_or_shutdown(&mut self, make_delay.delay_util(next)).await {
7073
break;
7174
}
7275
}

fastimer/src/schedule/mod.rs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
//! Repeatable and cancellable actions.
1616
1717
use std::future::Future;
18-
use std::time::Duration;
19-
20-
use crate::MakeDelay;
2118

2219
use self::select::Either;
2320
use self::select::select;
@@ -51,28 +48,7 @@ pub trait BaseAction: Send + 'static {
5148
}
5249

5350
/// Returns `true` if the action is shutdown.
54-
async fn initial_delay_or_shutdown<A, D>(
55-
action: &A,
56-
make_delay: &D,
57-
initial_delay: Option<Duration>,
58-
) -> bool
59-
where
60-
A: BaseAction,
61-
D: MakeDelay,
62-
{
63-
let Some(initial_delay) = initial_delay else {
64-
return false;
65-
};
66-
67-
if initial_delay.is_zero() {
68-
return false;
69-
}
70-
71-
delay_or_shutdown(action, make_delay.delay(initial_delay)).await
72-
}
73-
74-
/// Returns `true` if the action is shutdown.
75-
async fn delay_or_shutdown<A, D>(action: &A, delay: D) -> bool
51+
async fn delay_or_shutdown<A, D>(action: &mut A, delay: D) -> bool
7652
where
7753
A: BaseAction,
7854
D: Future<Output = ()>,

fastimer/src/schedule/notify.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use crate::Spawn;
2020
use crate::debug;
2121
use crate::info;
2222
use crate::schedule::BaseAction;
23+
use crate::schedule::delay_or_shutdown;
2324
use crate::schedule::execute_or_shutdown;
24-
use crate::schedule::initial_delay_or_shutdown;
2525

2626
/// Repeatable action that can be scheduled by notifications.
2727
///
@@ -63,8 +63,12 @@ pub trait NotifyActionExt: NotifyAction {
6363
);
6464

6565
'schedule: {
66-
if initial_delay_or_shutdown(&mut self, make_delay, initial_delay).await {
67-
break 'schedule;
66+
if let Some(initial_delay) = initial_delay {
67+
if initial_delay > Duration::ZERO
68+
&& delay_or_shutdown(&mut self, make_delay.delay(initial_delay)).await
69+
{
70+
break 'schedule;
71+
}
6872
}
6973

7074
loop {

fastimer/src/schedule/simple.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use crate::make_instant_from_now;
2525
use crate::schedule::BaseAction;
2626
use crate::schedule::delay_or_shutdown;
2727
use crate::schedule::execute_or_shutdown;
28-
use crate::schedule::initial_delay_or_shutdown;
2928

3029
/// Repeatable action.
3130
///
@@ -59,8 +58,12 @@ pub trait SimpleActionExt: SimpleAction {
5958
);
6059

6160
'schedule: {
62-
if initial_delay_or_shutdown(&mut self, &make_delay, initial_delay).await {
63-
break 'schedule;
61+
if let Some(initial_delay) = initial_delay {
62+
if initial_delay > Duration::ZERO
63+
&& delay_or_shutdown(&mut self, make_delay.delay(initial_delay)).await
64+
{
65+
break 'schedule;
66+
}
6467
}
6568

6669
loop {

0 commit comments

Comments
 (0)