Skip to content

Commit abb80bc

Browse files
authored
fix: make client clone, remove &mut self from subscribe (#88)
1 parent c04edc3 commit abb80bc

File tree

7 files changed

+11
-9
lines changed

7 files changed

+11
-9
lines changed

examples-wasm/examples/subscriptions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async fn main() {
5757

5858
let connection = Connection::new(ws_conn).await;
5959

60-
let (mut client, actor) = Client::build(connection).await.unwrap();
60+
let (client, actor) = Client::build(connection).await.unwrap();
6161
wasm_bindgen_futures::spawn_local(actor.into_future());
6262

6363
let mut stream = client.subscribe(build_query()).await.unwrap();

examples/examples/cynic-mulitiple-subscriptions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ async fn main() {
5555

5656
println!("Connected");
5757

58-
let (mut client, actor) = Client::build(connection).await.unwrap();
58+
let (client, actor) = Client::build(connection).await.unwrap();
5959
async_std::task::spawn(actor.into_future());
6060

6161
// In reality you'd probably want to different subscriptions, but for the sake of this example

examples/examples/tokio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async fn main() {
5454

5555
println!("Connected");
5656

57-
let (mut client, actor) = Client::build(connection).await.unwrap();
57+
let (client, actor) = Client::build(connection).await.unwrap();
5858
tokio::spawn(actor.into_future());
5959

6060
let mut stream = client.subscribe(build_query()).await.unwrap();

src/next/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl ClientBuilder {
105105
where
106106
Operation: GraphqlOperation + Unpin + Send + 'static,
107107
{
108-
let (mut client, actor) = self.await?;
108+
let (client, actor) = self.await?;
109109

110110
let mut actor_future = actor.into_future().fuse();
111111

src/next/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub use self::{
4747
/// }
4848
/// # Ok(())
4949
/// # }
50+
#[derive(Clone)]
5051
pub struct Client {
5152
actor: mpsc::Sender<ConnectionCommand>,
5253
subscription_buffer_size: usize,
@@ -69,7 +70,7 @@ impl Client {
6970
///
7071
/// Returns a `Stream` of responses.
7172
pub async fn subscribe<'a, Operation>(
72-
&mut self,
73+
&self,
7374
op: Operation,
7475
) -> Result<Subscription<Operation>, Error>
7576
where
@@ -87,7 +88,8 @@ impl Client {
8788
let request = serde_json::to_string(&message)
8889
.map_err(|error| Error::Serializing(error.to_string()))?;
8990

90-
self.actor
91+
let mut actor = self.actor.clone();
92+
actor
9193
.send(ConnectionCommand::Subscribe {
9294
request,
9395
sender,
@@ -102,7 +104,7 @@ impl Client {
102104
op.decode(response)
103105
.map_err(|err| Error::Decode(err.to_string()))
104106
})),
105-
actor: self.actor.clone(),
107+
actor,
106108
})
107109
}
108110

tests/cynic-tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async fn main_test() {
7272

7373
println!("Connected");
7474

75-
let (mut client, actor) = graphql_ws_client::Client::build(connection).await.unwrap();
75+
let (client, actor) = graphql_ws_client::Client::build(connection).await.unwrap();
7676

7777
tokio::spawn(actor.into_future());
7878

tests/graphql-client-tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async fn main_test() {
3737

3838
println!("Connected");
3939

40-
let (mut client, actor) = graphql_ws_client::Client::build(connection).await.unwrap();
40+
let (client, actor) = graphql_ws_client::Client::build(connection).await.unwrap();
4141

4242
tokio::spawn(actor.into_future());
4343

0 commit comments

Comments
 (0)