-
Notifications
You must be signed in to change notification settings - Fork 4
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
with_shutdown
for Tokio app
#113
Conversation
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.
Looks very good and concise, just a little thing to look at.
humphrey/src/tokio/app.rs
Outdated
sd.cancelled().await | ||
} else { | ||
loop { | ||
let _ = tokio::time::sleep(std::time::Duration::from_secs(9999)); |
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.
If you're trying to express "future that never resolves" you should use future::pending
I think.
For what it's worth, I don't do much Rust async either, but I thought it would be good for people to have the option of using Humphrey with the whole Tokio ecosystem. For example, it was particularly awkward (near impossible) to use it with lots of database connection crates that rely heavily on async before I added the Tokio feature. |
34b7b5c
to
a266ff0
Compare
Ah, that makes a lot of sense. I was wondering why adding the bloat/dependencies when it goes against the default case. I pushed with |
humphrey/src/tokio/app.rs
Outdated
.with_peer_result(stream.peer_addr()), | ||
); | ||
let shutdown = async { | ||
if let Some(sd) = self.shutdown.clone() { |
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.
Can we change the .clone()
to .as_ref()
? Just to avoid the unnecessary allocation.
CI ran too! Nice. |
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.
Great, thank you so much for all your work on this!
I don't do much rust async. I find it overly annoying for little benefit. One of the reasons I found this crate was it's one of the few that don't have page long dependency trees, super simple, and low-latency.
I pulled in https://docs.rs/tokio-util/latest/tokio_util/sync/struct.CancellationToken.html
which is part of the tokio project https://github.com/tokio-rs/tokio/tree/master/tokio-util
as I think this might be exactly what we're looking for.