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

Add run_ephemeral #995

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/server.rs
Expand Up @@ -129,11 +129,19 @@ where
{
/// Run this `Server` forever on the current thread.
pub async fn run(self, addr: impl Into<SocketAddr>) {
self.run_ephemeral(addr).1.await;
}

/// Run this `Server` on a possibly-ephemeral port, returning the port binding.
pub fn run_ephemeral(
self,
addr: impl Into<SocketAddr>,
) -> (SocketAddr, impl Future<Output = ()>) {
let (addr, fut) = self.bind_ephemeral(addr);
let span = tracing::info_span!("Server::run", ?addr);
tracing::info!(parent: &span, "listening on http://{}", addr);

fut.instrument(span).await;
(addr, fut.instrument(span))
}

/// Run this `Server` forever on the current thread with a specific stream
Expand Down