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

Feature request: expose an access to http server handle #547

Closed
slumber opened this issue Nov 2, 2021 · 2 comments · Fixed by #550
Closed

Feature request: expose an access to http server handle #547

slumber opened this issue Nov 2, 2021 · 2 comments · Fixed by #550

Comments

@slumber
Copy link
Contributor

slumber commented Nov 2, 2021

Call to HttpServer::start consumes the server, spawns a task and gives you a StopHandle.
As far as I see it, there's no easy way to simply "run forever"? tokio join handle is private, StopHandle doesn't implement Future, probably I miss something, but this looks a little bit inconvenient.

I'd propose to rename StopHandle into ServerHandle and make it awaitable the same way it works in actix:
HttpServer::run returns Server which can be used to stop the server or can be awaited on to run the application forever (since it implements Future).

@niklasad1
Copy link
Member

As far as I see it, there's no easy way to simply "run forever"?

Ok, I see you make a good point. Right, you need to keep the stop handle somewhere otherwise it will shutdown when it's dropped that might be annoying yes.

tokio join handle is private, StopHandle doesn't implement Future, probably I miss something, but this looks a little bit inconvenient.

I don't get what you mean by private you can just await on the tokio::JoinHandle because it impls Future, such as:

if let Ok(stop) = server.stop() {
  stop.await.unwrap();
}

I'd propose to rename StopHandle into ServerHandle and make it awaitable the same way it works in actix:
HttpServer::run returns Server which can be used to stop the server or can be awaited on to run the application forever (since it implements Future).

Sounds like a good idea to me, it was done this to have a "uniform API" with WsServer but perhaps we can change both.
What do you think @maciejhirsz?

@slumber
Copy link
Contributor Author

slumber commented Nov 2, 2021

I don't get what you mean by private you can just await on the tokio::JoinHandle because it impls Future, such as:

if let Ok(stop) = server.stop() {
  stop.await.unwrap();
}

I mean the underlying join handle could be used for running the server forever, but it's private (which totally makes sense). In your example, at this point handle is only returned after sending the shutdown signal.

Sounds like a good idea to me, it was done this to have a "uniform API" with WsServer but perhaps we can change both. What do you think @maciejhirsz?

I could submit a PR if the proposal gets approved

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 a pull request may close this issue.

2 participants