Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add keepalive to Torii client gRPC connections #2690

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion crates/torii/client/src/client/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod error;

use std::sync::Arc;
use std::time::Duration;

use dojo_types::WorldMetadata;
use dojo_world::contracts::WorldContractReader;
Expand Down Expand Up @@ -41,8 +42,10 @@
rpc_url: String,
relay_url: String,
world: Felt,
keepalive: Option<Duration>,

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

View check run for this annotation

Codecov / codecov/patch

crates/torii/client/src/client/mod.rs#L45

Added line #L45 was not covered by tests
) -> Result<Self, Error> {
let mut grpc_client = torii_grpc::client::WorldClient::new(torii_url, world).await?;
let mut grpc_client =
torii_grpc::client::WorldClient::new(torii_url, world, keepalive).await?;

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

View check run for this annotation

Codecov / codecov/patch

crates/torii/client/src/client/mod.rs#L47-L48

Added lines #L47 - L48 were not covered by tests

let relay_client = torii_relay::client::RelayClient::new(relay_url)?;

Expand Down
12 changes: 9 additions & 3 deletions crates/torii/grpc/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Client implementation for the gRPC service.
use std::num::ParseIntError;
use std::time::Duration;

use futures_util::stream::MapOk;
use futures_util::{Stream, StreamExt, TryStreamExt};
Expand Down Expand Up @@ -49,9 +50,14 @@

impl WorldClient {
#[cfg(not(target_arch = "wasm32"))]
pub async fn new(dst: String, world_address: Felt) -> Result<Self, Error> {
let endpoint =
Endpoint::from_shared(dst.clone()).map_err(|e| Error::Endpoint(e.to_string()))?;
pub async fn new(
dst: String,
world_address: Felt,
keepalive: Option<Duration>,
) -> Result<Self, Error> {
let endpoint = Endpoint::from_shared(dst.clone())
.map_err(|e| Error::Endpoint(e.to_string()))?
.tcp_keepalive(keepalive);

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

View check run for this annotation

Codecov / codecov/patch

crates/torii/grpc/src/client.rs#L53-L60

Added lines #L53 - L60 were not covered by tests
let channel = endpoint.connect().await.map_err(Error::Transport)?;
Ok(Self {
_world_address: world_address,
Expand Down
Loading