@@ -6,13 +6,7 @@ use structures::performance::STARTUP_TIME;
66use term:: { Manager , ManagerMessage } ;
77use tokio:: select;
88
9- use std:: {
10- future:: Future ,
11- panic,
12- path:: { Path , PathBuf } ,
13- str:: FromStr ,
14- sync:: RwLock ,
15- } ;
9+ use std:: { future:: Future , panic, path:: { Path , PathBuf } , str:: FromStr , sync:: RwLock } ;
1610use systems:: { logger:: init, player:: player_system} ;
1711
1812use crate :: {
@@ -30,7 +24,8 @@ mod structures;
3024mod systems;
3125mod term;
3226mod utils;
33-
27+ mod shutdown;
28+ pub use shutdown:: { ShutdownSignal , is_shutdown_sent, shutdown} ;
3429mod tasks;
3530
3631pub use database:: DATABASE ;
@@ -41,28 +36,18 @@ use mimalloc::MiMalloc;
4136#[ global_allocator]
4237static GLOBAL : MiMalloc = MiMalloc ;
4338
44- pub static SIGNALING_STOP : Lazy < ( Sender < ( ) > , Receiver < ( ) > ) > = Lazy :: new ( flume:: unbounded) ;
45-
4639fn run_service < T > ( future : T ) -> tokio:: task:: JoinHandle < ( ) >
4740where
4841 T : Future + Send + ' static ,
4942{
5043 tokio:: task:: spawn ( async move {
5144 select ! {
5245 _ = future => { } ,
53- _ = SIGNALING_STOP . 1 . recv_async ( ) => { } ,
46+ _ = ShutdownSignal => { } ,
5447 }
5548 } )
5649}
5750
58- fn shutdown ( ) {
59- info ! ( "Shutdown signal sending" ) ;
60- for _ in 0 ..1000 {
61- SIGNALING_STOP . 0 . send ( ( ) ) . unwrap ( ) ;
62- }
63- info ! ( "Shutdown signal sent" ) ;
64- }
65-
6651static COOKIES : Lazy < RwLock < Option < String > > > = Lazy :: new ( || RwLock :: new ( None ) ) ;
6752
6853pub fn try_get_cookies ( ) -> Option < String > {
@@ -247,7 +232,7 @@ async fn app_start_main(updater_r: Receiver<ManagerMessage>, updater_s: Sender<M
247232 let ( sa, player) = player_system ( updater_s. clone ( ) ) ;
248233 // Spawn the downloader system
249234 DOWNLOAD_MANAGER . spawn_system (
250- SIGNALING_STOP . 1 . clone ( ) ,
235+ ShutdownSignal ,
251236 download_manager_handler ( sa. clone ( ) ) ,
252237 ) ;
253238 STARTUP_TIME . log ( "Spawned system task" ) ;
@@ -279,7 +264,7 @@ fn app_start() {
279264 . block_on ( async move {
280265 select ! {
281266 _ = app_start_main( updater_r, updater_s) => { } ,
282- _ = SIGNALING_STOP . 1 . recv_async ( ) => { } ,
267+ _ = ShutdownSignal => { } ,
283268 } ;
284269 } ) ;
285270 info ! ( "Runtime closed" ) ;
0 commit comments