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