]> git.proxmox.com Git - proxmox.git/commitdiff
src/server/state.rs: switch to async
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 23 Aug 2019 11:41:38 +0000 (13:41 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 2 Sep 2019 13:21:26 +0000 (15:21 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/server/state.rs

index 3f8e47e6b4344a91bb7664e899c3422a556c5707..79b85e41fa0ccfc9efd1515af3d6ab2c501f663c 100644 (file)
@@ -3,9 +3,9 @@ use lazy_static::lazy_static;
 use std::sync::Mutex;
 
 use futures::*;
-use futures::stream::Stream;
 
-use tokio_signal::unix::{Signal, SIGHUP, SIGINT};
+// FIXME: with the next bump `Signal::new` becomes a freestanding function `signal()`
+use tokio_net::signal::unix::{Signal, SignalKind};
 
 use crate::tools::{self, BroadcastData};
 
@@ -36,33 +36,33 @@ lazy_static! {
 
 pub fn server_state_init() -> Result<(), Error> {
 
-    let stream = Signal::new(SIGINT).flatten_stream();
+    let stream = Signal::new(SignalKind::interrupt())?;
 
     let future = stream.for_each(|_| {
         println!("got shutdown request (SIGINT)");
         SERVER_STATE.lock().unwrap().reload_request = false;
         tools::request_shutdown();
-        Ok(())
-    }).map_err(|_| {});
+        futures::future::ready(())
+    });
 
     let abort_future = last_worker_future().map_err(|_| {});
-    let task = future.select(abort_future);
+    let task = futures::future::select(future, abort_future);
 
-    tokio::spawn(task.map(|_| {}).map_err(|_| {}));
+    tokio::spawn(task.map(|_| ()));
 
-    let stream = Signal::new(SIGHUP).flatten_stream();
+    let stream = Signal::new(SignalKind::hangup())?;
 
     let future = stream.for_each(|_| {
         println!("got reload request (SIGHUP)");
         SERVER_STATE.lock().unwrap().reload_request = true;
         tools::request_shutdown();
-        Ok(())
-    }).map_err(|_| {});
+        futures::future::ready(())
+    });
 
     let abort_future = last_worker_future().map_err(|_| {});
-    let task = future.select(abort_future);
+    let task = futures::future::select(future, abort_future);
 
-    tokio::spawn(task.map(|_| {}).map_err(|_| {}));
+    tokio::spawn(task.map(|_| ()));
 
     Ok(())
 }
@@ -91,13 +91,15 @@ pub fn server_shutdown() {
     check_last_worker();
 }
 
-pub fn shutdown_future() -> impl Future<Item=(), Error=Error> {
+pub fn shutdown_future() -> impl Future<Output = ()> {
     let mut data = SERVER_STATE.lock().unwrap();
-    data.shutdown_listeners.listen()
+    data
+        .shutdown_listeners
+        .listen()
+        .map(|_| ())
 }
 
-pub fn last_worker_future() ->  impl Future<Item=(), Error=Error> {
-
+pub fn last_worker_future() ->  impl Future<Output = Result<(), Error>> {
     let mut data = SERVER_STATE.lock().unwrap();
     data.last_worker_listeners.listen()
 }