Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/ws/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use callback::Arg;
use callback::Callback;
use log::*;
use serde::Serialize;
use std::cmp;
use std::net::TcpStream;
use std::sync::mpsc::Receiver;
use std::{sync::mpsc, thread, time::Duration};
Expand Down Expand Up @@ -161,7 +162,12 @@ where
}

// Subscribe
ws.write_message(Message::Text(subscription(topics)))?;
const SUBSCRIBE_BATCH_SIZE: usize = 10;
for i in (0..topics.len()).step_by(SUBSCRIBE_BATCH_SIZE) {
let after_last = cmp::min(i + SUBSCRIBE_BATCH_SIZE, topics.len());
let batch = &topics[i..after_last];
ws.write_message(Message::Text(subscription(batch)))?;
}

let rx = ping();
loop {
Expand Down Expand Up @@ -220,10 +226,10 @@ fn auth_req(credentials: &Credentials) -> String {
serde_json::to_string(&auth_req).unwrap()
}

fn subscription(topics: &Vec<String>) -> String {
fn subscription(topics: &[String]) -> String {
let sub = Op {
op: "subscribe",
args: topics.clone(),
args: topics.to_vec(),
};
serde_json::to_string(&sub).unwrap()
}
Expand Down