Skip to content

Commit 84045cd

Browse files
committed
feat: add per-request timeout overrides to all request builders
Adds .timeout(Duration) to all unary and streaming request builders (CheckPermission, WriteRelationships, DeleteRelationships, LookupResources, LookupSubjects, ReadRelationships, ExpandPermissionTree, Watch, BulkCheckPermissions, BulkExportRelationships). Per-request timeout overrides the client default via tonic::Request::set_timeout. Closes #2
1 parent b66eeed commit 84045cd

3 files changed

Lines changed: 144 additions & 10 deletions

File tree

src/client/experimental.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! may still evolve.
66
77
use std::collections::HashMap;
8+
use std::time::Duration;
89

910
use futures_core::Stream;
1011
use tokio_stream::StreamExt;
@@ -61,6 +62,7 @@ pub struct BulkCheckPermissionsRequest<'a> {
6162
items: Vec<proto::CheckBulkPermissionsRequestItem>,
6263
consistency: Option<proto::Consistency>,
6364
with_tracing: bool,
65+
timeout: Option<Duration>,
6466
}
6567

6668
impl<'a> BulkCheckPermissionsRequest<'a> {
@@ -75,6 +77,12 @@ impl<'a> BulkCheckPermissionsRequest<'a> {
7577
self.with_tracing = enabled;
7678
self
7779
}
80+
81+
/// Sets a per-request timeout, overriding the client default for this request.
82+
pub fn timeout(mut self, timeout: Duration) -> Self {
83+
self.timeout = Some(timeout);
84+
self
85+
}
7886
}
7987

8088
impl<'a> std::future::IntoFuture for BulkCheckPermissionsRequest<'a> {
@@ -84,12 +92,17 @@ impl<'a> std::future::IntoFuture for BulkCheckPermissionsRequest<'a> {
8492

8593
fn into_future(self) -> Self::IntoFuture {
8694
Box::pin(async move {
87-
let req = proto::CheckBulkPermissionsRequest {
95+
let proto_req = proto::CheckBulkPermissionsRequest {
8896
consistency: self.consistency,
8997
items: self.items,
9098
with_tracing: self.with_tracing,
9199
};
92100

101+
let mut req = tonic::Request::new(proto_req);
102+
if let Some(t) = self.timeout {
103+
req.set_timeout(t);
104+
}
105+
93106
let response = self
94107
.client
95108
.permissions
@@ -181,6 +194,7 @@ pub struct BulkExportRelationshipsRequest<'a> {
181194
client: &'a Client,
182195
filter: Option<proto::RelationshipFilter>,
183196
consistency: Option<proto::Consistency>,
197+
timeout: Option<Duration>,
184198
}
185199

186200
impl<'a> BulkExportRelationshipsRequest<'a> {
@@ -190,15 +204,26 @@ impl<'a> BulkExportRelationshipsRequest<'a> {
190204
self
191205
}
192206

207+
/// Sets a per-request timeout, overriding the client default for this request.
208+
pub fn timeout(mut self, timeout: Duration) -> Self {
209+
self.timeout = Some(timeout);
210+
self
211+
}
212+
193213
/// Sends the request and returns a stream of relationships.
194214
pub async fn send(self) -> Result<impl Stream<Item = Result<Relationship, Error>>, Error> {
195-
let req = proto::ExportBulkRelationshipsRequest {
215+
let proto_req = proto::ExportBulkRelationshipsRequest {
196216
consistency: self.consistency,
197217
optional_limit: 0,
198218
optional_cursor: None,
199219
optional_relationship_filter: self.filter,
200220
};
201221

222+
let mut req = tonic::Request::new(proto_req);
223+
if let Some(t) = self.timeout {
224+
req.set_timeout(t);
225+
}
226+
202227
let response = self
203228
.client
204229
.permissions
@@ -255,6 +280,7 @@ impl Client {
255280
items: proto_items,
256281
consistency: None,
257282
with_tracing: false,
283+
timeout: None,
258284
}
259285
}
260286

@@ -283,6 +309,7 @@ impl Client {
283309
client: self,
284310
filter: Some((&filter).into()),
285311
consistency: None,
312+
timeout: None,
286313
}
287314
}
288315
}

0 commit comments

Comments
 (0)