ソースを参照

Convert another panic to error handling.
Compatibility fix for Rust 1.33.

Konstantin Seiler 4 年 前
コミット
a52092e094
2 ファイル変更9 行追加6 行削除
  1. 5 1
      connect/src/spirc.rs
  2. 4 5
      src/main.rs

+ 5 - 1
connect/src/spirc.rs

@@ -333,7 +333,11 @@ impl Future for SpircTask {
                         progress = true;
                         self.handle_frame(frame);
                     }
-                    Async::Ready(None) => panic!("subscription terminated"),
+                    Async::Ready(None) => {
+                        error!("subscription terminated");
+                        self.shutdown = true;
+                        self.commands.close();
+                    },
                     Async::NotReady => (),
                 }
 

+ 4 - 5
src/main.rs

@@ -502,21 +502,20 @@ impl Future for Main {
                 progress = true;
             }
 
-            let mut try_to_reconnect = false;
+            let mut drop_spirc_and_try_to_reconnect = false;
             if let Some(ref mut spirc_task) = self.spirc_task {
                 if let Async::Ready(()) = spirc_task.poll().unwrap() {
                     if self.shutdown {
                         return Ok(Async::Ready(()));
                     } else {
                         warn!("Spirc shut down unexpectedly");
-                        self.spirc_task = None;
-
-                        try_to_reconnect = true;
+                        drop_spirc_and_try_to_reconnect = true;
                     }
                     progress = true;
                 }
             }
-            if try_to_reconnect {
+            if drop_spirc_and_try_to_reconnect {
+                self.spirc_task = None;
                 while (!self.auto_connect_times.is_empty()) && ((Instant::now() - self.auto_connect_times[0]).as_secs() > 600) {
                     let _ = self.auto_connect_times.remove(0);
                 }