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 #17

Open
wants to merge 3 commits into
base: 00-chat-route-b
Choose a base branch
from
Open

Conversation

willcrichton
Copy link
Contributor

@willcrichton willcrichton commented Jul 30, 2024

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
Contributor 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
Contributor 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.

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.

1 participant