Skip to content

Commit

Permalink
feat: add unsubscribe to event messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Apr 22, 2024
1 parent 99b0526 commit b637576
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/torii/client/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ impl Client {
Ok(stream)
}

/// Unsuscribe to entities updates of a World.
pub async fn unsubscribe_entities(&self, ids: Vec<FieldElement>) -> Result<(), Error> {
let mut grpc_client = self.inner.write().await;
grpc_client.unsubscribe_entities(ids).await?;
Ok(())
}

Check warning on line 166 in crates/torii/client/src/client/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/client/src/client/mod.rs#L162-L166

Added lines #L162 - L166 were not covered by tests

/// A direct stream to grpc subscribe event messages
pub async fn on_event_message_updated(
&self,
Expand All @@ -168,6 +175,13 @@ impl Client {
Ok(stream)
}

/// Unsuscribe to event messages updates of a World.
pub async fn unsubscribe_event_messages(&self, ids: Vec<FieldElement>) -> Result<(), Error> {
let mut grpc_client = self.inner.write().await;
grpc_client.unsubscribe_event_messages(ids).await?;
Ok(())
}

Check warning on line 183 in crates/torii/client/src/client/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/client/src/client/mod.rs#L179-L183

Added lines #L179 - L183 were not covered by tests

/// Returns the value of a model.
///
/// This function will only return `None`, if `model` doesn't exist. If there is no model with
Expand Down
26 changes: 26 additions & 0 deletions crates/torii/grpc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ impl WorldClient {
}))))
}

/// Unsuscribe to entities updates of a World.
pub async fn unsubscribe_entities(
&mut self,
hashed_keys: Vec<FieldElement>,
) -> Result<(), Error> {
let hashed_keys = hashed_keys.iter().map(|hashed| hashed.to_bytes_be().to_vec()).collect();
self.inner
.unsubscribe_entities(SubscribeEntitiesRequest { hashed_keys })
.await
.map_err(Error::Grpc)
.map(|_| ())
}

Check warning on line 128 in crates/torii/grpc/src/client.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/grpc/src/client.rs#L118-L128

Added lines #L118 - L128 were not covered by tests

/// Subscribe to event messages of a World.
pub async fn subscribe_event_messages(
&mut self,
Expand All @@ -133,6 +146,19 @@ impl WorldClient {
}))))
}

/// Unsuscribe to event messages of a World.
pub async fn unsubscribe_event_messages(
&mut self,
hashed_keys: Vec<FieldElement>,
) -> Result<(), Error> {
let hashed_keys = hashed_keys.iter().map(|hashed| hashed.to_bytes_be().to_vec()).collect();
self.inner
.unsubscribe_event_messages(SubscribeEntitiesRequest { hashed_keys })
.await
.map_err(Error::Grpc)
.map(|_| ())
}

Check warning on line 160 in crates/torii/grpc/src/client.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/grpc/src/client.rs#L150-L160

Added lines #L150 - L160 were not covered by tests

/// Subscribe to the model diff for a set of models of a World.
pub async fn subscribe_model_diffs(
&mut self,
Expand Down

0 comments on commit b637576

Please sign in to comment.