Skip to content
This repository has been archived by the owner on Jan 17, 2020. It is now read-only.

Cloning channels in public interface. #172

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion examples/gcloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn main() -> Result<(), io::Error> {
.set_keep_alive(10)
.set_security_opts(security_options);

let (mut mqtt_client, notifications) = MqttClient::start(mqtt_options).unwrap();
let (mqtt_client, notifications) = MqttClient::start(mqtt_options).unwrap();
let topic = "/devices/".to_owned() + &config.id + "/events/imu";

thread::spawn(move || {
Expand Down
2 changes: 1 addition & 1 deletion examples/httpconnect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn main() {
.set_reconnect_opts(reconnect_options)
.set_proxy(proxy);

let (mut mqtt_client, notifications) = MqttClient::start(mqtt_options).unwrap();
let (mqtt_client, notifications) = MqttClient::start(mqtt_options).unwrap();

mqtt_client.subscribe("hello/world", QoS::AtLeastOnce).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion examples/keepalive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() {
.set_keep_alive(10)
.set_reconnect_opts(reconnect_options);

let (mut mqtt_client, notifications) = MqttClient::start(mqtt_options).unwrap();
let (mqtt_client, notifications) = MqttClient::start(mqtt_options).unwrap();
thread::spawn(move || {
thread::sleep(Duration::from_secs(2));

Expand Down
6 changes: 3 additions & 3 deletions examples/playpause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ fn main() {
pretty_env_logger::init();
let mqtt_options = MqttOptions::new("test-id", "127.0.0.1", 1883).set_keep_alive(10);

let (mut mqtt_client, notifications) = MqttClient::start(mqtt_options).unwrap();
let (mqtt_client, notifications) = MqttClient::start(mqtt_options).unwrap();

mqtt_client.subscribe("hello/world", QoS::AtLeastOnce).unwrap();

let mut c1 = mqtt_client.clone();
let mut c2 = mqtt_client.clone();
let c1 = mqtt_client.clone();
let c2 = mqtt_client.clone();

thread::spawn(move || {
let dur = Duration::new(1, 0);
Expand Down
2 changes: 1 addition & 1 deletion examples/pubsub1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() {
.set_reconnect_opts(reconnection_options)
.set_clean_session(false);

let (mut mqtt_client, notifications) = MqttClient::start(mqtt_options).unwrap();
let (mqtt_client, notifications) = MqttClient::start(mqtt_options).unwrap();
mqtt_client.subscribe("hello/world", QoS::AtLeastOnce).unwrap();

thread::spawn(move || {
Expand Down
2 changes: 1 addition & 1 deletion examples/pubsub2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{thread, time::Duration};
fn main() {
pretty_env_logger::init();
let mqtt_options = MqttOptions::new("test-pubsub2", "127.0.0.1", 1883).set_keep_alive(10);
let (mut mqtt_client, notifications) = MqttClient::start(mqtt_options).unwrap();
let (mqtt_client, notifications) = MqttClient::start(mqtt_options).unwrap();

//mqtt_client.subscribe("hello/world", QoS::ExactlyOnce).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion examples/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{thread, time::Duration};
fn main() {
pretty_env_logger::init();
let mqtt_options = MqttOptions::new("test-id", "127.0.0.1", 1883).set_keep_alive(30);
let (mut mqtt_client, notifications) = MqttClient::start(mqtt_options).unwrap();
let (mqtt_client, notifications) = MqttClient::start(mqtt_options).unwrap();
let (done_tx, done_rx) = crossbeam_channel::bounded(1);

mqtt_client.subscribe("hello/world", QoS::AtLeastOnce).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion examples/shutdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fn main() {
pretty_env_logger::init();
let mqtt_options = MqttOptions::new("test-id-1", "localhost", 1883).set_keep_alive(10);

let (mut mqtt_client, notifications) = MqttClient::start(mqtt_options).unwrap();
let (mqtt_client, notifications) = MqttClient::start(mqtt_options).unwrap();

thread::spawn(move || {
thread::sleep(Duration::from_secs(5));
Expand Down
2 changes: 1 addition & 1 deletion examples/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() {
.set_client_auth(client_cert, client_key)
.set_keep_alive(10);

let (mut mqtt_client, notifications) = MqttClient::start(mqtt_options).unwrap();
let (mqtt_client, notifications) = MqttClient::start(mqtt_options).unwrap();
let topic = "hello/world";

thread::spawn(move || {
Expand Down
24 changes: 12 additions & 12 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl MqttClient {
}

/// Requests the eventloop for mqtt publish
pub fn publish<S, V, B>(&mut self, topic: S, qos: QoS, retained: B, payload: V) -> Result<(), ClientError>
pub fn publish<S, V, B>(&self, topic: S, qos: QoS, retained: B, payload: V) -> Result<(), ClientError>
where
S: Into<String>,
V: Into<Vec<u8>>,
Expand All @@ -122,13 +122,13 @@ impl MqttClient {
payload: Arc::new(payload),
};

let tx = &mut self.request_tx;
let tx = self.request_tx.clone();
tx.send(Request::Publish(publish)).wait()?;
Ok(())
}

/// Requests the eventloop for mqtt subscribe
pub fn subscribe<S>(&mut self, topic: S, qos: QoS) -> Result<(), ClientError>
pub fn subscribe<S>(&self, topic: S, qos: QoS) -> Result<(), ClientError>
where
S: Into<String>,
{
Expand All @@ -141,13 +141,13 @@ impl MqttClient {
topics: vec![topic],
};

let tx = &mut self.request_tx;
let tx = self.request_tx.clone();
tx.send(Request::Subscribe(subscribe)).wait()?;
Ok(())
}

/// Requests the eventloop for mqtt unsubscribe
pub fn unsubscribe<S>(&mut self, topic: S) -> Result<(), ClientError>
pub fn unsubscribe<S>(&self, topic: S) -> Result<(), ClientError>
where
S: Into<String>,
{
Expand All @@ -156,7 +156,7 @@ impl MqttClient {
topics: vec![topic.into()],
};

let tx = &mut self.request_tx;
let tx = self.request_tx.clone();
tx.send(Request::Unsubscribe(unsubscribe)).wait()?;
Ok(())
}
Expand All @@ -166,24 +166,24 @@ impl MqttClient {
/// network for reconnection
///
/// [Resume]: struct.MqttClient.html#method.resume
pub fn pause(&mut self) -> Result<(), ClientError> {
let tx = &mut self.command_tx;
pub fn pause(&self) -> Result<(), ClientError> {
let tx = self.command_tx.clone();
tx.send(Command::Pause).wait()?;
Ok(())
}

/// Commands the network eventloop to reconnect to the broker and
/// resume network io
pub fn resume(&mut self) -> Result<(), ClientError> {
let tx = &mut self.command_tx;
pub fn resume(&self) -> Result<(), ClientError> {
let tx = self.command_tx.clone();
tx.send(Command::Resume).wait()?;
Ok(())
}

/// Commands the network eventloop to gracefully shutdown
/// the connection to the broker.
pub fn shutdown(&mut self) -> Result<(), ClientError> {
let tx = &mut self.request_tx;
pub fn shutdown(&self) -> Result<(), ClientError> {
let tx = self.request_tx.clone();
tx.send(Request::Disconnect).wait()?;
Ok(())
}
Expand Down