Make Service.interrupt async
This commit is contained in:
@@ -100,13 +100,13 @@ impl crate::Service for Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TODO: not unwind safe
|
//TODO: not unwind safe
|
||||||
self.interrupt();
|
self.interrupt().await;
|
||||||
self.console_auto_stop().await;
|
self.console_auto_stop().await;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interrupt(&self) {
|
async fn interrupt(&self) {
|
||||||
#[cfg(feature = "console")]
|
#[cfg(feature = "console")]
|
||||||
self.console.interrupt();
|
self.console.interrupt();
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ impl crate::Service for Service {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interrupt(&self) {
|
async fn interrupt(&self) {
|
||||||
let (timer_sender, _) = &self.timer_channel;
|
let (timer_sender, _) = &self.timer_channel;
|
||||||
if !timer_sender.is_closed() {
|
if !timer_sender.is_closed() {
|
||||||
timer_sender.close();
|
timer_sender.close();
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ impl crate::Service for Service {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interrupt(&self) {
|
async fn interrupt(&self) {
|
||||||
for (sender, _) in &self.channels {
|
for (sender, _) in &self.channels {
|
||||||
if !sender.is_closed() {
|
if !sender.is_closed() {
|
||||||
sender.close();
|
sender.close();
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ pub(crate) trait Service: Any + Send + Sync {
|
|||||||
|
|
||||||
/// Interrupt the service. This is sent to initiate a graceful shutdown.
|
/// Interrupt the service. This is sent to initiate a graceful shutdown.
|
||||||
/// The service worker should return from its work loop.
|
/// The service worker should return from its work loop.
|
||||||
fn interrupt(&self) {}
|
async fn interrupt(&self) {}
|
||||||
|
|
||||||
/// Clear any caches or similar runtime state.
|
/// Clear any caches or similar runtime state.
|
||||||
async fn clear_cache(&self) {}
|
async fn clear_cache(&self) {}
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ impl Services {
|
|||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.interrupt();
|
self.interrupt().await;
|
||||||
if let Some(manager) = self.manager.lock().await.as_ref() {
|
if let Some(manager) = self.manager.lock().await.as_ref() {
|
||||||
manager.stop().await;
|
manager.stop().await;
|
||||||
}
|
}
|
||||||
@@ -263,12 +263,12 @@ impl Services {
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interrupt(&self) {
|
async fn interrupt(&self) {
|
||||||
debug!("Interrupting services...");
|
debug!("Interrupting services...");
|
||||||
for service in self.services() {
|
for service in self.services() {
|
||||||
let name = service.name();
|
let name = service.name();
|
||||||
trace!("Interrupting {name}");
|
trace!("Interrupting {name}");
|
||||||
service.interrupt();
|
service.interrupt().await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user