Skip to content

Commit 7a66eba

Browse files
First pass at a select statement (#51)
* First pass at a select statement
1 parent f2506da commit 7a66eba

File tree

11 files changed

+1010
-137
lines changed

11 files changed

+1010
-137
lines changed

src/context/macro_support.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use crate::endpoint::ContextInternal;
2+
use restate_sdk_shared_core::NotificationHandle;
3+
4+
// Sealed future trait, used by select statement
5+
#[doc(hidden)]
6+
pub trait SealedDurableFuture {
7+
fn inner_context(&self) -> ContextInternal;
8+
fn handle(&self) -> NotificationHandle;
9+
}

src/context/mod.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ use crate::serde::{Deserialize, Serialize};
66
use std::future::Future;
77
use std::time::Duration;
88

9+
#[doc(hidden)]
10+
pub mod macro_support;
911
mod request;
1012
mod run;
13+
mod select;
14+
1115
pub use request::{CallFuture, InvocationHandle, Request, RequestTarget};
1216
pub use run::{RunClosure, RunFuture, RunRetryPolicy};
1317

@@ -249,7 +253,10 @@ impl<'ctx> WorkflowContext<'ctx> {
249253
/// </details>
250254
pub trait ContextTimers<'ctx>: private::SealedContext<'ctx> {
251255
/// Sleep using Restate
252-
fn sleep(&self, duration: Duration) -> impl Future<Output = Result<(), TerminalError>> + 'ctx {
256+
fn sleep(
257+
&self,
258+
duration: Duration,
259+
) -> impl DurableFuture<Output = Result<(), TerminalError>> + 'ctx {
253260
private::SealedContext::inner_context(self).sleep(duration)
254261
}
255262
}
@@ -632,7 +639,7 @@ pub trait ContextAwakeables<'ctx>: private::SealedContext<'ctx> {
632639
&self,
633640
) -> (
634641
String,
635-
impl Future<Output = Result<T, TerminalError>> + Send + 'ctx,
642+
impl DurableFuture<Output = Result<T, TerminalError>> + Send + 'ctx,
636643
) {
637644
self.inner_context().awakeable()
638645
}
@@ -918,7 +925,7 @@ pub trait ContextPromises<'ctx>: private::SealedContext<'ctx> {
918925
fn promise<T: Deserialize + 'static>(
919926
&'ctx self,
920927
key: &str,
921-
) -> impl Future<Output = Result<T, TerminalError>> + 'ctx {
928+
) -> impl DurableFuture<Output = Result<T, TerminalError>> + 'ctx {
922929
self.inner_context().promise(key)
923930
}
924931

@@ -946,9 +953,10 @@ impl<'ctx, CTX: private::SealedContext<'ctx> + private::SealedCanUsePromises> Co
946953
{
947954
}
948955

949-
mod private {
950-
use super::*;
956+
pub trait DurableFuture: Future + macro_support::SealedDurableFuture {}
951957

958+
pub(crate) mod private {
959+
use super::*;
952960
pub trait SealedContext<'ctx> {
953961
fn inner_context(&self) -> &'ctx ContextInternal;
954962

src/context/request.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use super::DurableFuture;
2+
13
use crate::endpoint::ContextInternal;
24
use crate::errors::TerminalError;
35
use crate::serde::{Deserialize, Serialize};
@@ -95,7 +97,7 @@ impl<'a, Req, Res> Request<'a, Req, Res> {
9597
}
9698

9799
/// Call a service. This returns a future encapsulating the response.
98-
pub fn call(self) -> impl CallFuture<Result<Res, TerminalError>> + Send
100+
pub fn call(self) -> impl CallFuture<Response = Res> + Send
99101
where
100102
Req: Serialize + 'static,
101103
Res: Deserialize + 'static,
@@ -132,4 +134,8 @@ pub trait InvocationHandle {
132134
fn cancel(&self) -> impl Future<Output = Result<(), TerminalError>> + Send;
133135
}
134136

135-
pub trait CallFuture<O>: Future<Output = O> + InvocationHandle {}
137+
pub trait CallFuture:
138+
DurableFuture<Output = Result<Self::Response, TerminalError>> + InvocationHandle
139+
{
140+
type Response;
141+
}

0 commit comments

Comments
 (0)