diff options
| -rw-r--r-- | talpid-core/src/tunnel_state_machine/disconnecting_state.rs | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/talpid-core/src/tunnel_state_machine/disconnecting_state.rs b/talpid-core/src/tunnel_state_machine/disconnecting_state.rs index 12e0bebe5e..7ddbdcf5da 100644 --- a/talpid-core/src/tunnel_state_machine/disconnecting_state.rs +++ b/talpid-core/src/tunnel_state_machine/disconnecting_state.rs @@ -196,16 +196,24 @@ impl TunnelState for DisconnectingState { ) -> EventConsequence { use self::EventConsequence::*; - if self.tunnel_close_event.is_terminated() { - return NewState(self.after_disconnect(None, shared_values)); - } - - let result = runtime.block_on(async { - futures::select! { - command = commands.next() => EventResult::Command(command), - result = &mut self.tunnel_close_event => EventResult::Close(result), + let result = if self.tunnel_close_event.is_terminated() { + if commands.is_done() { + EventResult::Close(Ok(None)) + } else { + if let Ok(command) = commands.get_mut().try_next() { + EventResult::Command(command) + } else { + EventResult::Close(Ok(None)) + } } - }); + } else { + runtime.block_on(async { + futures::select! { + command = commands.next() => EventResult::Command(command), + result = &mut self.tunnel_close_event => EventResult::Close(result), + } + }) + }; match result { EventResult::Command(command) => self.handle_commands(command, shared_values), |
