@@ -72,6 +72,7 @@ impl fmt::Display for RequestTarget {
72
72
pub struct Request < ' a , Req , Res = ( ) > {
73
73
ctx : & ' a ContextInternal ,
74
74
request_target : RequestTarget ,
75
+ idempotency_key : Option < String > ,
75
76
req : Req ,
76
77
res : PhantomData < Res > ,
77
78
}
@@ -81,40 +82,54 @@ impl<'a, Req, Res> Request<'a, Req, Res> {
81
82
Self {
82
83
ctx,
83
84
request_target,
85
+ idempotency_key : None ,
84
86
req,
85
87
res : PhantomData ,
86
88
}
87
89
}
88
90
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
+
89
97
/// Call a service. This returns a future encapsulating the response.
90
98
pub fn call ( self ) -> impl CallFuture < Result < Res , TerminalError > > + Send
91
99
where
92
100
Req : Serialize + ' static ,
93
101
Res : Deserialize + ' static ,
94
102
{
95
- self . ctx . call ( self . request_target , self . req )
103
+ self . ctx
104
+ . call ( self . request_target , self . idempotency_key , self . req )
96
105
}
97
106
98
107
/// Send the request to the service, without waiting for the response.
99
108
pub fn send ( self ) -> impl InvocationHandle
100
109
where
101
110
Req : Serialize + ' static ,
102
111
{
103
- self . ctx . send ( self . request_target , self . req , None )
112
+ self . ctx
113
+ . send ( self . request_target , self . idempotency_key , self . req , None )
104
114
}
105
115
106
116
/// Schedule the request to the service, without waiting for the response.
107
117
pub fn send_after ( self , delay : Duration ) -> impl InvocationHandle
108
118
where
109
119
Req : Serialize + ' static ,
110
120
{
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
+ )
112
127
}
113
128
}
114
129
115
130
pub trait InvocationHandle {
116
131
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 ;
118
133
}
119
134
120
135
pub trait CallFuture < O > : Future < Output = O > + InvocationHandle { }
0 commit comments