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

Port miniserve to async #2

Merged
merged 3 commits into from
Dec 20, 2024
Merged

Port miniserve to async #2

merged 3 commits into from
Dec 20, 2024

Conversation

ovstinga
Copy link
Owner

Change the miniserve API to use Rust's async features via Tokio. Unfortunately, this breaks the server crate, so CI is failing.

pub trait Handler: Fn(Request) -> Response + Send + Sync + 'static {}
pub trait Handler: Fn(Request) -> Self::Future + Send + Sync + 'static {
type Future: Future<Output = Response> + Send + Sync + 'static;
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a close look at the change to the Handler trait. Previously, a handler was a function that took a request and returned a response. Now, a handler is a function that takes a request and returns a future which eventually returns a response.

pub fn run(self) {
let listener =
TcpListener::bind("127.0.0.1:3000").expect("Failed to connect to 127.0.0.1:3000");
pub async fn run(self) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the run function is now asynchronous, indicated by the async keyword.

@ovstinga ovstinga mentioned this pull request Dec 20, 2024
@ovstinga ovstinga merged commit c0ea6df into main Dec 20, 2024
1 check failed
ovstinga added a commit that referenced this pull request Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants