Skip to main content

serve

Function serve 

Source
pub async fn serve(
    addr: impl ToSocketAddrs,
    dispatcher: impl Dispatcher,
) -> Result<(), Error>
๐Ÿ‘ŽDeprecated since 0.16.0:

it cannot be stopped: use Server::bind(addr).await?.serve_with_shutdown(dispatcher, shutdown_signal()); removed no earlier than 0.17.0

Expand description

Starts an HTTP server that dispatches requests using the given dispatcher, and never stops.

Binds a TCP listener on addr and serves it with a Server under ServeConfig::default(). Once the listener is bound this function does not return, and dropping its future stops accepting without ending the work in flight or draining the connections.

Deprecated in 0.16.0 (ADR 0052), removed no earlier than 0.17.0. The same server, with a graceful stop:

use a2a_protocol_server::serve::{Server, shutdown_signal};
let report = Server::bind("127.0.0.1:3000")
    .await?
    .serve_with_shutdown(dispatcher, shutdown_signal())
    .await;
if let Some(why) = report.refused {
    return Err(std::io::Error::other(why));
}

ยงErrors

Returns std::io::Error if the TCP listener fails to bind. This is the only way the returned future completes.