Skip to content

Commit 76f8311

Browse files
committed
Move to nightly rust to access async closures
Motivation ---------- A primary design pattern that we want to use is currently challenging due to asybc closures not being supported in stable rust. In order to make this pattern possible we should switch to nightly and enable the feature. async_closures should be moved to stable before we need to release the SDK. Changes -------- Specify the nightly toolchain. Enable async_closures feature. Use async closures.
1 parent 6174bd5 commit 76f8311

File tree

5 files changed

+28
-34
lines changed

5 files changed

+28
-34
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ jobs:
2929
steps:
3030
- uses: actions/checkout@v3
3131

32+
- name: Update Rust Toolchain Target
33+
run: |
34+
echo "targets = ['${{matrix.target}}']" >> rust-toolchain.toml
35+
3236
- name: Setup Rust toolchain and cache
3337
uses: actions-rust-lang/setup-rust-toolchain@v1.4.3
3438
with:

rust-toolchain.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[toolchain]
2+
channel = "nightly"

sdk/couchbase-core/src/kvclientmanager.rs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,8 @@ where
239239
let client = manager.get_client(endpoint.clone()).await?;
240240

241241
let res = operation(client.clone()).await;
242-
match res {
243-
Ok(r) => {
244-
return Ok(r);
245-
}
242+
return match res {
243+
Ok(r) => Ok(r),
246244
Err(e) => {
247245
if let Some(memdx_err) = e.is_memdx_error() {
248246
if memdx_err.is_dispatch_error() {
@@ -257,20 +255,9 @@ where
257255
}
258256
}
259257

260-
return Err(e);
258+
Err(e)
261259
}
262-
}
263-
}
264-
}
265-
266-
pub(crate) struct OrchestrateMemdClientAsyncFnMut {}
267-
268-
impl OrchestrateMemdClientAsyncFnMut {
269-
async fn call<K, Resp: TryFromClientResponse>(&mut self, client: Arc<K>) -> Result<Resp>
270-
where
271-
K: KvClient + KvClientOps + PartialEq + Sync + Send + 'static,
272-
{
273-
todo!()
260+
};
274261
}
275262
}
276263

@@ -357,7 +344,7 @@ mod tests {
357344
let result = orchestrate_memd_client(
358345
&manager,
359346
"192.168.107.128:11210".to_string(),
360-
|client: Arc<StdKvClient<Client>>| async move {
347+
async |client: Arc<StdKvClient<Client>>| {
361348
client
362349
.set(SetRequest {
363350
collection_id: 0,
@@ -379,7 +366,7 @@ mod tests {
379366
.await
380367
.unwrap();
381368

382-
dbg!(result);
369+
// dbg!(result);
383370

384371
let client = manager
385372
.get_client("192.168.107.128:11210".to_string())

sdk/couchbase-core/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![feature(async_closure)]
2+
13
pub mod authenticator;
24
pub mod cbconfig;
35
mod configparser;

sdk/couchbase-core/src/vbucketrouter.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ pub(crate) trait NotMyVbucketConfigHandler {
7979

8080
pub(crate) async fn orchestrate_memd_routing<V, Resp: TryFromClientResponse, Fut>(
8181
vb: &V,
82-
ch: Option<Arc<impl NotMyVbucketConfigHandler>>,
82+
nmvb_handler: Arc<impl NotMyVbucketConfigHandler>,
8383
key: &[u8],
8484
vb_server_idx: u32,
85-
mut operation: impl FnMut(String, u16) -> Fut,
85+
mut operation: impl Fn(String, u16) -> Fut,
8686
) -> Result<Resp>
8787
where
8888
V: VbucketRouter,
@@ -96,12 +96,6 @@ where
9696
Err(e) => e,
9797
};
9898

99-
let ch = ch.clone();
100-
101-
if ch.is_none() {
102-
return Err(err);
103-
}
104-
10599
let config = if let Some(memdx_err) = err.is_memdx_error() {
106100
if memdx_err.is_notmyvbucket_error() {
107101
if let Some(config) = memdx_err.has_server_config() {
@@ -134,7 +128,9 @@ where
134128
}
135129
};
136130

137-
ch.unwrap().not_my_vbucket_config(config_json, &endpoint);
131+
nmvb_handler
132+
.clone()
133+
.not_my_vbucket_config(config_json, &endpoint);
138134

139135
let (new_endpoint, new_vb_id) = vb.dispatch_by_key(key, vb_server_idx)?;
140136
if new_endpoint == endpoint && new_vb_id == vb_id {
@@ -280,16 +276,19 @@ mod tests {
280276

281277
let dispatcher = StdVbucketRouter::new(routing_info, VbucketRouterOptions {});
282278

279+
// let dispatcher = Arc::new(dispatcher);
280+
// let manager = Arc::new(manager);
281+
283282
let set_result = orchestrate_memd_routing(
284283
&dispatcher,
285-
Some(Arc::new(NVMBHandler {})),
284+
Arc::new(NVMBHandler {}),
286285
b"test",
287286
0,
288-
|endpoint: String, vb_id: u16| async {
287+
async |endpoint: String, vb_id: u16| {
289288
orchestrate_memd_client(
290289
&manager,
291290
endpoint,
292-
|client: Arc<StdKvClient<Client>>| async move {
291+
async |client: Arc<StdKvClient<Client>>| {
293292
client
294293
.set(SetRequest {
295294
collection_id: 0,
@@ -318,14 +317,14 @@ mod tests {
318317

319318
let get_result = orchestrate_memd_routing(
320319
&dispatcher,
321-
Some(Arc::new(NVMBHandler {})),
320+
Arc::new(NVMBHandler {}),
322321
b"test",
323322
0,
324-
|endpoint: String, vb_id: u16| async {
323+
async |endpoint: String, vb_id: u16| {
325324
orchestrate_memd_client(
326325
&manager,
327326
endpoint,
328-
|client: Arc<StdKvClient<Client>>| async move {
327+
async |client: Arc<StdKvClient<Client>>| {
329328
client
330329
.get(GetRequest {
331330
collection_id: 0,

0 commit comments

Comments
 (0)