Skip to content
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

Merged
merged 2 commits into from
Jan 5, 2024
Merged

Conversation

Grinkers
Copy link
Contributor

@Grinkers Grinkers commented Jan 4, 2024

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.

Copy link
Owner

@w-henderson w-henderson left a 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.

sd.cancelled().await
} else {
loop {
let _ = tokio::time::sleep(std::time::Duration::from_secs(9999));
Copy link
Owner

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.

@w-henderson
Copy link
Owner

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.

@Grinkers Grinkers marked this pull request as ready for review January 5, 2024 00:27
@Grinkers
Copy link
Contributor Author

Grinkers commented Jan 5, 2024

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.

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 future::pending and marked ready for review.

.with_peer_result(stream.peer_addr()),
);
let shutdown = async {
if let Some(sd) = self.shutdown.clone() {
Copy link
Owner

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.

@Grinkers
Copy link
Contributor Author

Grinkers commented Jan 5, 2024

CI ran too! Nice.

Copy link
Owner

@w-henderson w-henderson left a 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!

@w-henderson w-henderson merged commit 101cc62 into w-henderson:master Jan 5, 2024
5 checks passed
@Grinkers Grinkers deleted the shutdown-tokio branch January 5, 2024 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants