Skip to content

Commit

Permalink
keeping smol for now to run client alter method synchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
lhr0909 committed May 14, 2020
1 parent f9129cb commit 617ad7a
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 15 deletions.
172 changes: 172 additions & 0 deletions native/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ serde_derive = "1.0.106"
serde_json = "1.0.52"
dgraph-tonic = { git = "https://github.com/xanthous-tech/dgraph-tonic", branch = "expose-traits" }
tokio = { version = "0.2", features = ["macros", "sync"] }
smol = { version = "0.1.4", features = ["tokio02"] }
tokio-global = "0.4.0"
nanoid = "0.3.0"
1 change: 1 addition & 0 deletions native/src/classes/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub struct DgraphClientWrapper {

impl DgraphClientWrapper {
pub fn alter(&self, op: Operation) -> Payload {
// TODO: consider making this async using tokio runtime
smol::run(async {
self.client.alter(op).await.expect("client alter failed")
})
Expand Down
5 changes: 2 additions & 3 deletions native/src/classes/txn.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::collections::HashMap;
use std::string::String;
use std::sync::{Arc, Mutex as StdMutex};
use std::thread;

use tokio_global::AutoRuntime;
use tokio::sync::Mutex;
Expand Down Expand Up @@ -165,7 +164,7 @@ impl<M> MutateTxnWrapper<M> where M: Mutate + 'static {
let resp_id = txn_id.clone();
let tx = self.response_tx.clone();

thread::spawn(move || smol::run(async {
async move {
let mut txn_guard = txn_arc_mutex.lock().await;
let txn = txn_guard.as_mut();

Expand All @@ -181,7 +180,7 @@ impl<M> MutateTxnWrapper<M> where M: Mutate + 'static {
Ok(()) => (),
Err(_) => ()
}
}));
}.spawn();

resp_id
}
Expand Down
23 changes: 12 additions & 11 deletions native/src/test_client.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
use dgraph_tonic::{Client, Query};

fn main() {
smol::run(async {
let client = Client::new("http://localhost:9080").expect("dgraph client");
#[tokio::main]
async fn main() {
let client = Client::new("http://localhost:9080").expect("dgraph client");

let mut txn = client.new_read_only_txn();
let mut txn = client.new_read_only_txn();

let q = r#"{
total(func: eq(dgraph.type, "Node")) {
count(uid)
}
}"#;
let q = r#"{
total(func: eq(dgraph.type, "Node")) {
count(uid)
}
}"#;

let response = txn.query(q).await.expect("query");
})
let response = txn.query(q).await.expect("query");

println!("response - {:?}", response);
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
"pre-commit": "lint-staged && npm run build && npm run build:typescript"
}
}
}

0 comments on commit 617ad7a

Please sign in to comment.