Skip to content

Move to nightly rust to access async closures #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Update Rust Toolchain Target
run: |
echo "targets = ['${{matrix.target}}']" >> rust-toolchain.toml

- name: Setup Rust toolchain and cache
uses: actions-rust-lang/setup-rust-toolchain@v1.4.3
with:
Expand Down
2 changes: 2 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "nightly"
25 changes: 6 additions & 19 deletions sdk/couchbase-core/src/kvclientmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,8 @@ where
let client = manager.get_client(endpoint.clone()).await?;

let res = operation(client.clone()).await;
match res {
Ok(r) => {
return Ok(r);
}
return match res {
Ok(r) => Ok(r),
Err(e) => {
if let Some(memdx_err) = e.is_memdx_error() {
if memdx_err.is_dispatch_error() {
Expand All @@ -257,20 +255,9 @@ where
}
}

return Err(e);
Err(e)
}
}
}
}

pub(crate) struct OrchestrateMemdClientAsyncFnMut {}

impl OrchestrateMemdClientAsyncFnMut {
async fn call<K, Resp: TryFromClientResponse>(&mut self, client: Arc<K>) -> Result<Resp>
where
K: KvClient + KvClientOps + PartialEq + Sync + Send + 'static,
{
todo!()
};
}
}

Expand Down Expand Up @@ -357,7 +344,7 @@ mod tests {
let result = orchestrate_memd_client(
&manager,
"192.168.107.128:11210".to_string(),
|client: Arc<StdKvClient<Client>>| async move {
async |client: Arc<StdKvClient<Client>>| {
client
.set(SetRequest {
collection_id: 0,
Expand All @@ -379,7 +366,7 @@ mod tests {
.await
.unwrap();

dbg!(result);
// dbg!(result);

let client = manager
.get_client("192.168.107.128:11210".to_string())
Expand Down
2 changes: 2 additions & 0 deletions sdk/couchbase-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(async_closure)]

pub mod authenticator;
pub mod cbconfig;
mod configparser;
Expand Down
29 changes: 14 additions & 15 deletions sdk/couchbase-core/src/vbucketrouter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ pub(crate) trait NotMyVbucketConfigHandler {

pub(crate) async fn orchestrate_memd_routing<V, Resp: TryFromClientResponse, Fut>(
vb: &V,
ch: Option<Arc<impl NotMyVbucketConfigHandler>>,
nmvb_handler: Arc<impl NotMyVbucketConfigHandler>,
key: &[u8],
vb_server_idx: u32,
mut operation: impl FnMut(String, u16) -> Fut,
mut operation: impl Fn(String, u16) -> Fut,
) -> Result<Resp>
where
V: VbucketRouter,
Expand All @@ -96,12 +96,6 @@ where
Err(e) => e,
};

let ch = ch.clone();

if ch.is_none() {
return Err(err);
}

let config = if let Some(memdx_err) = err.is_memdx_error() {
if memdx_err.is_notmyvbucket_error() {
if let Some(config) = memdx_err.has_server_config() {
Expand Down Expand Up @@ -134,7 +128,9 @@ where
}
};

ch.unwrap().not_my_vbucket_config(config_json, &endpoint);
nmvb_handler
.clone()
.not_my_vbucket_config(config_json, &endpoint);

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

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

// let dispatcher = Arc::new(dispatcher);
// let manager = Arc::new(manager);

let set_result = orchestrate_memd_routing(
&dispatcher,
Some(Arc::new(NVMBHandler {})),
Arc::new(NVMBHandler {}),
b"test",
0,
|endpoint: String, vb_id: u16| async {
async |endpoint: String, vb_id: u16| {
orchestrate_memd_client(
&manager,
endpoint,
|client: Arc<StdKvClient<Client>>| async move {
async |client: Arc<StdKvClient<Client>>| {
client
.set(SetRequest {
collection_id: 0,
Expand Down Expand Up @@ -318,14 +317,14 @@ mod tests {

let get_result = orchestrate_memd_routing(
&dispatcher,
Some(Arc::new(NVMBHandler {})),
Arc::new(NVMBHandler {}),
b"test",
0,
|endpoint: String, vb_id: u16| async {
async |endpoint: String, vb_id: u16| {
orchestrate_memd_client(
&manager,
endpoint,
|client: Arc<StdKvClient<Client>>| async move {
async |client: Arc<StdKvClient<Client>>| {
client
.get(GetRequest {
collection_id: 0,
Expand Down
Loading