mirror of
https://github.com/tokio-rs/axum.git
synced 2024-11-22 07:08:16 +01:00
Make into_future on Serve, WithGracefulShutdown independent of tokio (#2975)
This commit is contained in:
parent
b3cd8d066d
commit
a0f310a492
1 changed files with 26 additions and 10 deletions
|
@ -312,6 +312,7 @@ where
|
||||||
_marker: _,
|
_marker: _,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
|
private::ServeFuture(Box::pin(async move {
|
||||||
let (signal_tx, signal_rx) = watch::channel(());
|
let (signal_tx, signal_rx) = watch::channel(());
|
||||||
let signal_tx = Arc::new(signal_tx);
|
let signal_tx = Arc::new(signal_tx);
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
|
@ -322,7 +323,6 @@ where
|
||||||
|
|
||||||
let (close_tx, close_rx) = watch::channel(());
|
let (close_tx, close_rx) = watch::channel(());
|
||||||
|
|
||||||
private::ServeFuture(Box::pin(async move {
|
|
||||||
loop {
|
loop {
|
||||||
let (tcp_stream, remote_addr) = tokio::select! {
|
let (tcp_stream, remote_addr) = tokio::select! {
|
||||||
conn = tcp_accept(&tcp_listener) => {
|
conn = tcp_accept(&tcp_listener) => {
|
||||||
|
@ -597,4 +597,20 @@ mod tests {
|
||||||
assert_eq!(address.ip(), IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)));
|
assert_eq!(address.ip(), IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)));
|
||||||
assert_ne!(address.port(), 0);
|
assert_ne!(address.port(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn into_future_outside_tokio() {
|
||||||
|
let router: Router = Router::new();
|
||||||
|
let addr = "0.0.0.0:0";
|
||||||
|
|
||||||
|
let rt = tokio::runtime::Builder::new_multi_thread()
|
||||||
|
.enable_all()
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let listener = rt.block_on(tokio::net::TcpListener::bind(addr)).unwrap();
|
||||||
|
|
||||||
|
// Call Serve::into_future outside of a tokio context. This used to panic.
|
||||||
|
_ = serve(listener, router).into_future();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue