axum_test/util/
serve_handle.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use tokio::task::JoinHandle;

/// A handle to a running Axum service.
///
/// When the handle is dropped, it will attempt to terminate the service.
#[derive(Debug)]
pub struct ServeHandle {
    server_handle: JoinHandle<()>,
}

impl ServeHandle {
    pub(crate) fn new(server_handle: JoinHandle<()>) -> Self {
        Self { server_handle }
    }

    pub fn is_finished(&self) -> bool {
        self.server_handle.is_finished()
    }
}

impl Drop for ServeHandle {
    fn drop(&mut self) {
        self.server_handle.abort()
    }
}