Try to send something to the socket. If it fails, reconnect and send again.
(
&self,
mut client: WebSocketClient,
tx: tokio::sync::oneshot::Sender<Result<T, Error>>,
f: F,
)
| 142 | |
| 143 | /// Try to send something to the socket. If it fails, reconnect and send again. |
| 144 | async fn send_loop<F, T>( |
| 145 | &self, |
| 146 | mut client: WebSocketClient, |
| 147 | tx: tokio::sync::oneshot::Sender<Result<T, Error>>, |
| 148 | f: F, |
| 149 | ) -> WebSocketClient |
| 150 | where |
| 151 | F: Fn(WebSocketClient) -> Pin<Box<dyn Future<Output = Result<T, Error>> + Send>>, |
| 152 | { |
| 153 | loop { |
| 154 | match f(client.clone()).await { |
| 155 | Err(e) if matches!(e.detail(), ErrorDetail::ChannelSend(_)) => { |
| 156 | client = self.ws_client().await; |
| 157 | } |
| 158 | res => { |
| 159 | let _ = tx.send(res); |
| 160 | return client; |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | /// Connect to the WebSocket and start the driver, returning the client. |
| 167 | async fn ws_client(&self) -> WebSocketClient { |