use Notify instead of Sender
This commit is contained in:
@@ -1,11 +1,12 @@
|
|||||||
use bytes::{buf::Reader, Bytes};
|
use bytes::{buf::Reader, Bytes};
|
||||||
use std::sync::{Arc, Condvar, Mutex};
|
use std::sync::{Arc, Condvar, Mutex};
|
||||||
|
use tokio::sync::Notify;
|
||||||
|
|
||||||
use warp::http;
|
use warp::http;
|
||||||
|
|
||||||
pub struct HttpListener {
|
pub struct HttpListener {
|
||||||
pub incoming: std::sync::mpsc::Receiver<HttpRequest>,
|
pub incoming: std::sync::mpsc::Receiver<HttpRequest>,
|
||||||
pub warp_shutdown: tokio::sync::mpsc::Sender<()>,
|
pub warp_shutdown: Arc<Notify>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct HttpRequest {
|
pub struct HttpRequest {
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ use std::str::FromStr;
|
|||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
#[cfg(feature = "http")]
|
#[cfg(feature = "http")]
|
||||||
use std::sync::{Arc, Condvar, Mutex};
|
use std::sync::{Arc, Condvar, Mutex};
|
||||||
|
use tokio::sync::Notify;
|
||||||
|
|
||||||
use chrono::{offset::Local, DateTime};
|
use chrono::{offset::Local, DateTime};
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
@@ -4594,7 +4595,7 @@ impl Machine {
|
|||||||
let (tx, rx) = std::sync::mpsc::sync_channel(1024);
|
let (tx, rx) = std::sync::mpsc::sync_channel(1024);
|
||||||
|
|
||||||
// warp shutdown channel
|
// warp shutdown channel
|
||||||
let (warp_shutdown_tx, mut warp_shutdown_rx) = tokio::sync::mpsc::channel(1);
|
let warp_shutdown = Arc::new(Notify::new());
|
||||||
|
|
||||||
let runtime = tokio::runtime::Handle::current();
|
let runtime = tokio::runtime::Handle::current();
|
||||||
let _guard = runtime.enter();
|
let _guard = runtime.enter();
|
||||||
@@ -4657,6 +4658,7 @@ impl Machine {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let warp_shutdown_clone = warp_shutdown.clone();
|
||||||
runtime.spawn(async move {
|
runtime.spawn(async move {
|
||||||
match ssl_server {
|
match ssl_server {
|
||||||
Some((key, cert)) => {
|
Some((key, cert)) => {
|
||||||
@@ -4665,7 +4667,7 @@ impl Machine {
|
|||||||
.key(key)
|
.key(key)
|
||||||
.cert(cert)
|
.cert(cert)
|
||||||
.bind_with_graceful_shutdown(addr, async move {
|
.bind_with_graceful_shutdown(addr, async move {
|
||||||
warp_shutdown_rx.recv().await;
|
warp_shutdown_clone.notified().await;
|
||||||
});
|
});
|
||||||
|
|
||||||
tokio::task::spawn(server);
|
tokio::task::spawn(server);
|
||||||
@@ -4673,7 +4675,7 @@ impl Machine {
|
|||||||
None => {
|
None => {
|
||||||
let (_addr, server) =
|
let (_addr, server) =
|
||||||
warp::serve(serve).bind_with_graceful_shutdown(addr, async move {
|
warp::serve(serve).bind_with_graceful_shutdown(addr, async move {
|
||||||
warp_shutdown_rx.recv().await;
|
warp_shutdown_clone.notified().await;
|
||||||
});
|
});
|
||||||
|
|
||||||
tokio::task::spawn(server);
|
tokio::task::spawn(server);
|
||||||
@@ -4683,7 +4685,7 @@ impl Machine {
|
|||||||
|
|
||||||
let http_listener = HttpListener {
|
let http_listener = HttpListener {
|
||||||
incoming: rx,
|
incoming: rx,
|
||||||
warp_shutdown: warp_shutdown_tx,
|
warp_shutdown: warp_shutdown,
|
||||||
};
|
};
|
||||||
let http_listener: TypedArenaPtr<HttpListener> =
|
let http_listener: TypedArenaPtr<HttpListener> =
|
||||||
arena_alloc!(http_listener, &mut self.machine_st.arena);
|
arena_alloc!(http_listener, &mut self.machine_st.arena);
|
||||||
@@ -4706,7 +4708,7 @@ impl Machine {
|
|||||||
(HeapCellValueTag::Cons, cons_ptr) => {
|
(HeapCellValueTag::Cons, cons_ptr) => {
|
||||||
match_untyped_arena_ptr!(cons_ptr,
|
match_untyped_arena_ptr!(cons_ptr,
|
||||||
(ArenaHeaderTag::HttpListener, http_listener) => {
|
(ArenaHeaderTag::HttpListener, http_listener) => {
|
||||||
let _ = futures::executor::block_on(http_listener.warp_shutdown.send(()));
|
http_listener.warp_shutdown.notify_one();
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
|
|||||||
Reference in New Issue
Block a user