Skip to content

Commit 12b6bce

Browse files
This seems to be getting somewhere
1 parent 885826c commit 12b6bce

File tree

8 files changed

+647
-576
lines changed

8 files changed

+647
-576
lines changed

src/context/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ pub trait ContextAwakeables<'ctx>: private::SealedContext<'ctx> {
632632
&self,
633633
) -> (
634634
String,
635-
impl Future<Output = Result<T, TerminalError>> + Send + Sync + 'ctx,
635+
impl Future<Output = Result<T, TerminalError>> + Send + 'ctx,
636636
) {
637637
self.inner_context().awakeable()
638638
}

src/context/request.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ impl fmt::Display for RequestTarget {
7272
pub struct Request<'a, Req, Res = ()> {
7373
ctx: &'a ContextInternal,
7474
request_target: RequestTarget,
75+
idempotency_key: Option<String>,
7576
req: Req,
7677
res: PhantomData<Res>,
7778
}
@@ -81,40 +82,54 @@ impl<'a, Req, Res> Request<'a, Req, Res> {
8182
Self {
8283
ctx,
8384
request_target,
85+
idempotency_key: None,
8486
req,
8587
res: PhantomData,
8688
}
8789
}
8890

91+
/// Add idempotency key to the request
92+
pub fn idempotency_key(mut self, idempotency_key: impl Into<String>) -> Self {
93+
self.idempotency_key = Some(idempotency_key.into());
94+
self
95+
}
96+
8997
/// Call a service. This returns a future encapsulating the response.
9098
pub fn call(self) -> impl CallFuture<Result<Res, TerminalError>> + Send
9199
where
92100
Req: Serialize + 'static,
93101
Res: Deserialize + 'static,
94102
{
95-
self.ctx.call(self.request_target, self.req)
103+
self.ctx
104+
.call(self.request_target, self.idempotency_key, self.req)
96105
}
97106

98107
/// Send the request to the service, without waiting for the response.
99108
pub fn send(self) -> impl InvocationHandle
100109
where
101110
Req: Serialize + 'static,
102111
{
103-
self.ctx.send(self.request_target, self.req, None)
112+
self.ctx
113+
.send(self.request_target, self.idempotency_key, self.req, None)
104114
}
105115

106116
/// Schedule the request to the service, without waiting for the response.
107117
pub fn send_after(self, delay: Duration) -> impl InvocationHandle
108118
where
109119
Req: Serialize + 'static,
110120
{
111-
self.ctx.send(self.request_target, self.req, Some(delay))
121+
self.ctx.send(
122+
self.request_target,
123+
self.idempotency_key,
124+
self.req,
125+
Some(delay),
126+
)
112127
}
113128
}
114129

115130
pub trait InvocationHandle {
116131
fn invocation_id(&self) -> impl Future<Output = Result<String, TerminalError>> + Send;
117-
fn cancel(&self);
132+
fn cancel(&self) -> impl Future<Output = Result<(), TerminalError>> + Send;
118133
}
119134

120135
pub trait CallFuture<O>: Future<Output = O> + InvocationHandle {}

0 commit comments

Comments
 (0)