Skip to content

Commit 617ad7a

Browse files
committed
keeping smol for now to run client alter method synchronously
1 parent f9129cb commit 617ad7a

File tree

6 files changed

+189
-15
lines changed

6 files changed

+189
-15
lines changed

native/Cargo.lock

Lines changed: 172 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

native/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ serde_derive = "1.0.106"
2525
serde_json = "1.0.52"
2626
dgraph-tonic = { git = "https://github.com/xanthous-tech/dgraph-tonic", branch = "expose-traits" }
2727
tokio = { version = "0.2", features = ["macros", "sync"] }
28+
smol = { version = "0.1.4", features = ["tokio02"] }
2829
tokio-global = "0.4.0"
2930
nanoid = "0.3.0"

native/src/classes/client.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub struct DgraphClientWrapper {
77

88
impl DgraphClientWrapper {
99
pub fn alter(&self, op: Operation) -> Payload {
10+
// TODO: consider making this async using tokio runtime
1011
smol::run(async {
1112
self.client.alter(op).await.expect("client alter failed")
1213
})

native/src/classes/txn.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::collections::HashMap;
22
use std::string::String;
33
use std::sync::{Arc, Mutex as StdMutex};
4-
use std::thread;
54

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

168-
thread::spawn(move || smol::run(async {
167+
async move {
169168
let mut txn_guard = txn_arc_mutex.lock().await;
170169
let txn = txn_guard.as_mut();
171170

@@ -181,7 +180,7 @@ impl<M> MutateTxnWrapper<M> where M: Mutate + 'static {
181180
Ok(()) => (),
182181
Err(_) => ()
183182
}
184-
}));
183+
}.spawn();
185184

186185
resp_id
187186
}

native/src/test_client.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
use dgraph_tonic::{Client, Query};
22

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

7-
let mut txn = client.new_read_only_txn();
7+
let mut txn = client.new_read_only_txn();
88

9-
let q = r#"{
10-
total(func: eq(dgraph.type, "Node")) {
11-
count(uid)
12-
}
13-
}"#;
9+
let q = r#"{
10+
total(func: eq(dgraph.type, "Node")) {
11+
count(uid)
12+
}
13+
}"#;
1414

15-
let response = txn.query(q).await.expect("query");
16-
})
15+
let response = txn.query(q).await.expect("query");
16+
17+
println!("response - {:?}", response);
1718
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
},
6666
"husky": {
6767
"hooks": {
68-
"pre-commit": "lint-staged"
68+
"pre-commit": "lint-staged && npm run build && npm run build:typescript"
6969
}
7070
}
7171
}

0 commit comments

Comments
 (0)