Commit fd5653ac1d
Unsigned
Layout: unified · split
src/executor.rs +6 −5
| @@ -1,4 +1,4 @@ | ||
| 1 | use async_task; | |
| 1 | use async_task::JoinHandle; | |
| 2 | 2 | use pipe_channel::{channel, Receiver, Sender}; |
| 3 | 3 | use std::collections::VecDeque; |
| 4 | 4 | use std::future::Future; |
| @@ -33,10 +33,10 @@ static mut _FUTURE_QUEUE: Option<FutureQueue> = None; | ||
| 33 | 33 | |
| 34 | 34 | type FutureQueue = Arc<Mutex<VecDeque<Job>>>; |
| 35 | 35 | |
| 36 | pub fn spawn_weechat<F, T>(future: F) | |
| 36 | pub fn spawn_weechat<F, R>(future: F) -> JoinHandle<R, ()> | |
| 37 | 37 | where |
| 38 | F: Future<Output = T> + 'static, | |
| 39 | T: 'static, | |
| 38 | F: Future<Output = R> + 'static, | |
| 39 | R: 'static, | |
| 40 | 40 | { |
| 41 | 41 | let weechat = unsafe { Weechat::weechat() }; |
| 42 | 42 | |
| @@ -83,8 +83,9 @@ where | ||
| 83 | 83 | weechat_notify.send(()).unwrap(); |
| 84 | 84 | }; |
| 85 | 85 | |
| 86 | let (task, _handle) = async_task::spawn(future, schedule, ()); | |
| 86 | let (task, handle) = async_task::spawn(future, schedule, ()); | |
| 87 | 87 | task.schedule(); |
| 88 | handle | |
| 88 | 89 | } |
| 89 | 90 | |
| 90 | 91 | pub fn cleanup_executor() { |
src/server.rs +6 −2
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | use async_std::sync::channel as async_channel; |
| 2 | 2 | use async_std::sync::{Receiver, Sender}; |
| 3 | use async_task::JoinHandle; | |
| 3 | 4 | use std::collections::HashMap; |
| 4 | 5 | use std::time::Duration; |
| 5 | 6 | use tokio::runtime::Runtime; |
| @@ -50,6 +51,7 @@ pub struct LoginState { | ||
| 50 | 51 | |
| 51 | 52 | struct ConnectedState { |
| 52 | 53 | client_channel: Sender<ServerMessage>, |
| 54 | sync_receiver: JoinHandle<(), ()>, | |
| 53 | 55 | homeserver: Url, |
| 54 | 56 | runtime: Runtime, |
| 55 | 57 | } |
| @@ -95,13 +97,14 @@ impl MatrixServer { | ||
| 95 | 97 | |
| 96 | 98 | let (tx, rx) = async_channel(1000); |
| 97 | 99 | runtime.spawn(MatrixServer::sync_loop(client, tx)); |
| 98 | spawn_weechat(MatrixServer::sync_receiver(rx)); | |
| 100 | let sync_receiver_handle = | |
| 101 | spawn_weechat(MatrixServer::sync_receiver(rx)); | |
| 99 | 102 | |
| 100 | 103 | let (client_sender, client_receiver) = async_channel(10); |
| 101 | ||
| 102 | 104 | runtime.spawn(MatrixServer::send_loop(send_client, client_receiver)); |
| 103 | 105 | |
| 104 | 106 | self.connected_state = Some(ConnectedState { |
| 107 | sync_receiver: sync_receiver_handle, | |
| 105 | 108 | client_channel: client_sender, |
| 106 | 109 | homeserver, |
| 107 | 110 | runtime, |
| @@ -112,6 +115,7 @@ impl MatrixServer { | ||
| 112 | 115 | let connected_state = self.connected_state.take(); |
| 113 | 116 | if let Some(s) = connected_state { |
| 114 | 117 | s.runtime.shutdown_now(); |
| 118 | s.sync_receiver.cancel(); | |
| 115 | 119 | } |
| 116 | 120 | } |
| 117 | 121 | |