Skip to content

Commit

Permalink
fix: make client clone, remove &mut self from subscribe (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
obmarg authored Apr 9, 2024
1 parent c04edc3 commit abb80bc
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples-wasm/examples/subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async fn main() {

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

let (mut client, actor) = Client::build(connection).await.unwrap();
let (client, actor) = Client::build(connection).await.unwrap();
wasm_bindgen_futures::spawn_local(actor.into_future());

let mut stream = client.subscribe(build_query()).await.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/cynic-mulitiple-subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async fn main() {

println!("Connected");

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

// In reality you'd probably want to different subscriptions, but for the sake of this example
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async fn main() {

println!("Connected");

let (mut client, actor) = Client::build(connection).await.unwrap();
let (client, actor) = Client::build(connection).await.unwrap();
tokio::spawn(actor.into_future());

let mut stream = client.subscribe(build_query()).await.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/next/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl ClientBuilder {
where
Operation: GraphqlOperation + Unpin + Send + 'static,
{
let (mut client, actor) = self.await?;
let (client, actor) = self.await?;

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

Expand Down
8 changes: 5 additions & 3 deletions src/next/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub use self::{
/// }
/// # Ok(())
/// # }
#[derive(Clone)]
pub struct Client {
actor: mpsc::Sender<ConnectionCommand>,
subscription_buffer_size: usize,
Expand All @@ -69,7 +70,7 @@ impl Client {
///
/// Returns a `Stream` of responses.
pub async fn subscribe<'a, Operation>(
&mut self,
&self,
op: Operation,
) -> Result<Subscription<Operation>, Error>
where
Expand All @@ -87,7 +88,8 @@ impl Client {
let request = serde_json::to_string(&message)
.map_err(|error| Error::Serializing(error.to_string()))?;

self.actor
let mut actor = self.actor.clone();
actor
.send(ConnectionCommand::Subscribe {
request,
sender,
Expand All @@ -102,7 +104,7 @@ impl Client {
op.decode(response)
.map_err(|err| Error::Decode(err.to_string()))
})),
actor: self.actor.clone(),
actor,
})
}

Expand Down
2 changes: 1 addition & 1 deletion tests/cynic-tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async fn main_test() {

println!("Connected");

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

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

Expand Down
2 changes: 1 addition & 1 deletion tests/graphql-client-tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async fn main_test() {

println!("Connected");

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

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

Expand Down

0 comments on commit abb80bc

Please sign in to comment.