Skip to content

Commit c3d11c3

Browse files
committed
feat: add close()
1 parent f71d95a commit c3d11c3

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lazer/sdk/rust/client/examples/subscribe_price_feeds.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async fn main() -> anyhow::Result<()> {
4141
while let Some(msg) = stream.next().await {
4242
println!("Received update: {:?}", msg?);
4343
count += 1;
44-
if count >= 50 {
44+
if count >= 10 {
4545
break;
4646
}
4747
}
@@ -51,5 +51,6 @@ async fn main() -> anyhow::Result<()> {
5151
println!("Unsubscribed from {:?}", subscription_id);
5252

5353
tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
54+
client.close().await?;
5455
Ok(())
5556
}

lazer/sdk/rust/client/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,15 @@ impl LazerClient {
179179
anyhow::bail!("WebSocket connection not started")
180180
}
181181
}
182+
183+
/// Closes the WebSocket connection
184+
pub async fn close(&mut self) -> Result<()> {
185+
if let Some(sender) = &mut self.ws_sender {
186+
sender.send(Message::Close(None)).await?;
187+
self.ws_sender = None;
188+
Ok(())
189+
} else {
190+
anyhow::bail!("WebSocket connection not started")
191+
}
192+
}
182193
}

0 commit comments

Comments
 (0)