pub struct Router { /* private fields */ }
Expand description
The built router.
Construct this using Router::builder
.
When dropped, this will abort listening the tasks, so make sure to store it.
Even with this abort-on-drop behaviour, it’s recommended to call and await
Router::shutdown
before ending the process.
As an example for graceful shutdown, e.g. for tests or CLI tools,
wait for tokio::signal::ctrl_c()
:
let endpoint = Endpoint::builder().discovery_n0().bind().await?;
let router = Router::builder(endpoint)
// .accept(&ALPN, <something>)
.spawn();
// wait until the user wants to
tokio::signal::ctrl_c().await?;
router.shutdown().await?;
Implementations§
Source§impl Router
impl Router
Sourcepub fn is_shutdown(&self) -> bool
pub fn is_shutdown(&self) -> bool
Checks if the router is already shutdown.
Sourcepub async fn shutdown(&self) -> Result<()>
pub async fn shutdown(&self) -> Result<()>
Shuts down the accept loop cleanly.
When this function returns, all ProtocolHandler
s will be shutdown and
Endpoint::close
will have been called.
If already shutdown, it returns Ok
.
If some ProtocolHandler
panicked in the accept loop, this will propagate
that panic into the result here.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Router
impl !RefUnwindSafe for Router
impl Send for Router
impl Sync for Router
impl Unpin for Router
impl !UnwindSafe for Router
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more