Skip to content

Commit

Permalink
Make Command private
Browse files Browse the repository at this point in the history
  • Loading branch information
caspervonb committed May 3, 2023
1 parent 4239f5e commit d0f3eab
Showing 1 changed file with 1 addition and 36 deletions.
37 changes: 1 addition & 36 deletions async-nats/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ pub(crate) enum ServerOp {
}

#[derive(Debug)]
pub enum Command {
pub(crate) enum Command {
Publish {
subject: String,
payload: Bytes,
Expand All @@ -254,12 +254,10 @@ pub enum Command {
sid: u64,
max: Option<u64>,
},
Ping,
Flush {
result: oneshot::Sender<Result<(), io::Error>>,
},
TryFlush,
Connect(ConnectInfo),
}

/// `ClientOp` represents all actions of `Client`.
Expand Down Expand Up @@ -300,7 +298,6 @@ pub(crate) struct ConnectionHandler {
connector: Connector,
subscriptions: HashMap<u64, Subscription>,
pending_pings: usize,
max_pings: usize,
info_sender: tokio::sync::watch::Sender<ServerInfo>,
ping_interval: Interval,
flush_interval: Interval,
Expand All @@ -325,7 +322,6 @@ impl ConnectionHandler {
connector,
subscriptions: HashMap::new(),
pending_pings: 0,
max_pings: 2,
info_sender,
ping_interval,
flush_interval,
Expand Down Expand Up @@ -511,28 +507,6 @@ impl ConnectionHandler {
}
}
}
Command::Ping => {
debug!(
"PING command. Pending pings {}, max pings {}",
self.pending_pings, self.max_pings
);
self.pending_pings += 1;
self.ping_interval.reset();

if self.pending_pings > self.max_pings {
debug!(
"pending pings {}, max pings {}. disconnecting",
self.pending_pings, self.max_pings
);
self.handle_disconnect().await?;
}

if let Err(_err) = self.connection.write_op(&ClientOp::Ping).await {
self.handle_disconnect().await?;
}

self.handle_flush().await?;
}
Command::Flush { result } => {
if let Err(_err) = self.handle_flush().await {
if let Err(err) = self.handle_disconnect().await {
Expand Down Expand Up @@ -602,15 +576,6 @@ impl ConnectionHandler {
error!("Sending Publish failed with {:?}", err);
}
}
Command::Connect(connect_info) => {
while let Err(_err) = self
.connection
.write_op(&ClientOp::Connect(connect_info.clone()))
.await
{
self.handle_disconnect().await?;
}
}
}

Ok(())
Expand Down

0 comments on commit d0f3eab

Please sign in to comment.