-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
refactor(rt): Clean up Timer trait #3037
Conversation
@@ -20,16 +20,16 @@ pub trait Executor<Fut> { | |||
/// A timer which provides timer-like functions. | |||
pub trait Timer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated: Would it be good to have the resulting futures as an associated type rather than as a boxed future? Both tokio
and smol
have well-defined "sleep" types instead of async
methods, so we may be able to avoid an allocation here by not boxing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would require parameterizing the ~entire API over the timer trait which I'm not sure is desired.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a workaround, you could just do:
struct BoxedTimer {
inner: Box<dyn Timer<Sleep = Pin<Box<dyn Future>>>>>
}
But this might not be idiomatic, so I agree with your assessment.
Is there an assumption in hyper that the If this is expected, it would be nice to specify in the trait comment so implementors get this right. |
Any |
Fair enough, deregistering/cancelling the timer on |
This both avoids an unnecessary extra layer of boxing and removes some dubious unsafe code.
Closes #3028