Skip to content

Commit 885826c

Browse files
IDK what i'm doing here
1 parent 9151c75 commit 885826c

File tree

14 files changed

+396
-88
lines changed

14 files changed

+396
-88
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ default = ["http_server", "rand", "uuid"]
1212
hyper = ["dep:hyper", "http-body-util", "restate-sdk-shared-core/http"]
1313
http_server = ["hyper", "hyper/server", "hyper/http2", "hyper-util", "tokio/net", "tokio/signal", "tokio/macros"]
1414

15+
1516
[dependencies]
1617
bytes = "1.6.1"
1718
futures = "0.3"
@@ -23,8 +24,7 @@ pin-project-lite = "0.2"
2324
rand = { version = "0.8.5", optional = true }
2425
regress = "0.10"
2526
restate-sdk-macros = { version = "0.3.2", path = "macros" }
26-
restate-sdk-shared-core = "0.1.0"
27-
sha2 = "=0.11.0-pre.3"
27+
restate-sdk-shared-core = { git = "https://github.com/restatedev/sdk-shared-core.git", branch = "main", features = ["request_identity", "sha2_random_seed", "http"] }
2828
serde = "1.0"
2929
serde_json = "1.0"
3030
thiserror = "1.0.63"

examples/cron.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl PeriodicTaskImpl {
7777
.object_client::<PeriodicTaskClient>(context.key())
7878
.run()
7979
// And send with a delay
80-
.send_with_delay(Duration::from_secs(10));
80+
.send_after(Duration::from_secs(10));
8181
}
8282
}
8383

src/context/mod.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::time::Duration;
88

99
mod request;
1010
mod run;
11-
pub use request::{Request, RequestTarget};
11+
pub use request::{CallFuture, InvocationHandle, Request, RequestTarget};
1212
pub use run::{RunClosure, RunFuture, RunRetryPolicy};
1313

1414
pub type HeaderMap = http::HeaderMap<String>;
@@ -433,6 +433,11 @@ pub trait ContextClient<'ctx>: private::SealedContext<'ctx> {
433433
Request::new(self.inner_context(), request_target, req)
434434
}
435435

436+
/// Create an [`InvocationHandle`] from an invocation id.
437+
fn invocation_handle(&self, invocation_id: String) -> impl InvocationHandle + 'ctx {
438+
self.inner_context().invocation_handle(invocation_id)
439+
}
440+
436441
/// Create a service client. The service client is generated by the [`restate_sdk_macros::service`] macro with the same name of the trait suffixed with `Client`.
437442
///
438443
/// ```rust,no_run
@@ -454,7 +459,7 @@ pub trait ContextClient<'ctx>: private::SealedContext<'ctx> {
454459
/// client.handle().send();
455460
///
456461
/// // Schedule the request to be executed later
457-
/// client.handle().send_with_delay(Duration::from_secs(60));
462+
/// client.handle().send_after(Duration::from_secs(60));
458463
/// # }
459464
/// ```
460465
fn service_client<C>(&self) -> C
@@ -485,7 +490,7 @@ pub trait ContextClient<'ctx>: private::SealedContext<'ctx> {
485490
/// client.handle().send();
486491
///
487492
/// // Schedule the request to be executed later
488-
/// client.handle().send_with_delay(Duration::from_secs(60));
493+
/// client.handle().send_after(Duration::from_secs(60));
489494
/// # }
490495
/// ```
491496
fn object_client<C>(&self, key: impl Into<String>) -> C
@@ -516,7 +521,7 @@ pub trait ContextClient<'ctx>: private::SealedContext<'ctx> {
516521
/// client.handle().send();
517522
///
518523
/// // Schedule the request to be executed later
519-
/// client.handle().send_with_delay(Duration::from_secs(60));
524+
/// client.handle().send_after(Duration::from_secs(60));
520525
/// # }
521526
/// ```
522527
fn workflow_client<C>(&self, key: impl Into<String>) -> C

src/context/request.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<'a, Req, Res> Request<'a, Req, Res> {
8787
}
8888

8989
/// Call a service. This returns a future encapsulating the response.
90-
pub fn call(self) -> impl Future<Output = Result<Res, TerminalError>> + Send
90+
pub fn call(self) -> impl CallFuture<Result<Res, TerminalError>> + Send
9191
where
9292
Req: Serialize + 'static,
9393
Res: Deserialize + 'static,
@@ -96,18 +96,25 @@ impl<'a, Req, Res> Request<'a, Req, Res> {
9696
}
9797

9898
/// Send the request to the service, without waiting for the response.
99-
pub fn send(self)
99+
pub fn send(self) -> impl InvocationHandle
100100
where
101101
Req: Serialize + 'static,
102102
{
103103
self.ctx.send(self.request_target, self.req, None)
104104
}
105105

106106
/// Schedule the request to the service, without waiting for the response.
107-
pub fn send_with_delay(self, duration: Duration)
107+
pub fn send_after(self, delay: Duration) -> impl InvocationHandle
108108
where
109109
Req: Serialize + 'static,
110110
{
111-
self.ctx.send(self.request_target, self.req, Some(duration))
111+
self.ctx.send(self.request_target, self.req, Some(delay))
112112
}
113113
}
114+
115+
pub trait InvocationHandle {
116+
fn invocation_id(&self) -> impl Future<Output = Result<String, TerminalError>> + Send;
117+
fn cancel(&self);
118+
}
119+
120+
pub trait CallFuture<O>: Future<Output = O> + InvocationHandle {}

0 commit comments

Comments
 (0)