Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
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