Skip to content

Commit c42c71b

Browse files
committed
Update to latest tokio
1 parent d22fab7 commit c42c71b

File tree

9 files changed

+49
-50
lines changed

9 files changed

+49
-50
lines changed

integration_tests/async_await/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ async = []
1010
[dependencies]
1111
juniper = { path = "../../juniper", features = ["async"] }
1212
futures = "=0.3.1"
13-
tokio = "=0.2.0-alpha.6"
13+
tokio = { version = "0.2", features = ["rt-core", "time", "macros"] }

integration_tests/async_await/src/main.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ impl User {
3434
}
3535

3636
async fn delayed() -> bool {
37-
let when = tokio::clock::now() + std::time::Duration::from_millis(100);
38-
tokio::timer::delay(when).await;
37+
tokio::time::delay_for(std::time::Duration::from_millis(100)).await;
3938
true
4039
}
4140
}
@@ -61,8 +60,7 @@ impl Query {
6160
}
6261

6362
async fn delayed() -> bool {
64-
let when = tokio::clock::now() + std::time::Duration::from_millis(100);
65-
tokio::timer::delay(when).await;
63+
tokio::time::delay_for(std::time::Duration::from_millis(100)).await;
6664
true
6765
}
6866
}
@@ -72,14 +70,8 @@ struct Mutation;
7270
#[juniper::graphql_object]
7371
impl Mutation {}
7472

75-
fn run<O>(f: impl std::future::Future<Output = O>) -> O {
76-
tokio::runtime::current_thread::Runtime::new()
77-
.unwrap()
78-
.block_on(f)
79-
}
80-
81-
#[test]
82-
fn async_simple() {
73+
#[tokio::test]
74+
async fn async_simple() {
8375
let schema = RootNode::new(Query, Mutation);
8476
let doc = r#"
8577
query {
@@ -95,9 +87,9 @@ fn async_simple() {
9587
"#;
9688

9789
let vars = Default::default();
98-
let f = juniper::execute_async(doc, None, &schema, &vars, &());
99-
100-
let (res, errs) = run(f).unwrap();
90+
let (res, errs) = juniper::execute_async(doc, None, &schema, &vars, &())
91+
.await
92+
.unwrap();
10193

10294
assert!(errs.is_empty());
10395

juniper/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ uuid = { version = ">= 0.7, < 0.8", optional = true }
4848
[dev-dependencies]
4949
bencher = "0.1.2"
5050
serde_json = { version = "1.0.2" }
51-
tokio = "=0.2.0-alpha.6"
51+
tokio = { version = "0.2", features = ["macros", "rt-core", "time"] }

juniper/src/executor_tests/async_await/mod.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ impl User {
3535
}
3636

3737
async fn delayed() -> bool {
38-
let when = tokio::clock::now() + std::time::Duration::from_millis(100);
39-
tokio::timer::delay(when).await;
38+
tokio::time::delay_for(std::time::Duration::from_millis(100)).await;
4039
true
4140
}
4241
}
@@ -62,8 +61,7 @@ impl Query {
6261
}
6362

6463
async fn delayed() -> bool {
65-
let when = tokio::clock::now() + std::time::Duration::from_millis(100);
66-
tokio::timer::delay(when).await;
64+
tokio::time::delay_for(std::time::Duration::from_millis(100)).await;
6765
true
6866
}
6967
}
@@ -73,14 +71,8 @@ struct Mutation;
7371
#[crate::graphql_object_internal]
7472
impl Mutation {}
7573

76-
fn run<O>(f: impl std::future::Future<Output = O>) -> O {
77-
tokio::runtime::current_thread::Runtime::new()
78-
.unwrap()
79-
.block_on(f)
80-
}
81-
82-
#[test]
83-
fn async_simple() {
74+
#[tokio::test]
75+
async fn async_simple() {
8476
let schema = RootNode::new(Query, Mutation);
8577
let doc = r#"
8678
query {
@@ -94,9 +86,9 @@ fn async_simple() {
9486
"#;
9587

9688
let vars = Default::default();
97-
let f = crate::execute_async(doc, None, &schema, &vars, &());
98-
99-
let (res, errs) = run(f).unwrap();
89+
let (res, errs) = crate::execute_async(doc, None, &schema, &vars, &())
90+
.await
91+
.unwrap();
10092

10193
assert!(errs.is_empty());
10294

juniper_benchmarks/Cargo.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@ authors = ["Christoph Herzog <[email protected]>"]
55
edition = "2018"
66

77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8-
98
[[bench]]
109
name = "benchmark"
1110
harness = false
1211

1312
[features]
14-
async = ["juniper/async", "futures"]
13+
async = []
1514

1615
[dependencies]
17-
juniper = { path = "../juniper" }
18-
futures = { version = "=0.3.1", optional = true }
16+
juniper = { path = "../juniper", features = ["async"] }
17+
futures = "=0.3.1"
1918

2019
[dev-dependencies]
2120
criterion = "0.2.11"
22-
tokio = "=0.2.0-alpha.6"
21+
tokio = { version = "0.2.0", features = ["rt-threaded", "rt-core"] }

juniper_benchmarks/benches/benchmark.rs

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion, Parameter
55
use juniper::{graphql_value, InputValue, ToInputValue, Value};
66
use juniper_benchmarks as j;
77

8-
fn bench_sync_vs_async_single_user_flat_instant(c: &mut Criterion) {
9-
const QUERY: &'static str = r#"
8+
fn bench_sync_vs_async_users_flat_instant(c: &mut Criterion) {
9+
const ASYNC_QUERY: &'static str = r#"
1010
query Query($id: Int) {
11-
user(id: $id) {
11+
users_async_instant(ids: [$id]!) {
1212
id
1313
kind
1414
username
@@ -17,8 +17,19 @@ fn bench_sync_vs_async_single_user_flat_instant(c: &mut Criterion) {
1717
}
1818
"#;
1919

20+
const SYNC_QUERY: &'static str = r#"
21+
query Query($id: Int) {
22+
users_sync_instant(ids: [$id]!) {
23+
id
24+
kind
25+
username
26+
email
27+
}
28+
}
29+
"#;
30+
2031
c.bench(
21-
"Sync vs Async - Single User Flat - Instant",
32+
"Sync vs Async - Users Flat - Instant",
2233
ParameterizedBenchmark::new(
2334
"Sync",
2435
|b, count| {
@@ -28,15 +39,18 @@ fn bench_sync_vs_async_single_user_flat_instant(c: &mut Criterion) {
2839
let ids = InputValue::list(ids);
2940
b.iter(|| {
3041
j::execute(
31-
QUERY,
42+
SYNC_QUERY,
3243
vec![("ids".to_string(), ids.clone())].into_iter().collect(),
3344
)
3445
})
3546
},
3647
vec![1, 10],
3748
)
3849
.with_function("Async - Single Thread", |b, count| {
39-
let mut rt = tokio::runtime::current_thread::Runtime::new().unwrap();
50+
let mut rt = tokio::runtime::Builder::new()
51+
.basic_scheduler()
52+
.build()
53+
.unwrap();
4054

4155
let ids = (0..*count)
4256
.map(|x| InputValue::scalar(x as i32))
@@ -45,14 +59,17 @@ fn bench_sync_vs_async_single_user_flat_instant(c: &mut Criterion) {
4559

4660
b.iter(|| {
4761
let f = j::execute_async(
48-
QUERY,
62+
ASYNC_QUERY,
4963
vec![("ids".to_string(), ids.clone())].into_iter().collect(),
5064
);
5165
rt.block_on(f)
5266
})
5367
})
5468
.with_function("Async - Threadpool", |b, count| {
55-
let rt = tokio::runtime::Runtime::new().unwrap();
69+
let mut rt = tokio::runtime::Builder::new()
70+
.threaded_scheduler()
71+
.build()
72+
.unwrap();
5673

5774
let ids = (0..*count)
5875
.map(|x| InputValue::scalar(x as i32))
@@ -61,7 +78,7 @@ fn bench_sync_vs_async_single_user_flat_instant(c: &mut Criterion) {
6178

6279
b.iter(|| {
6380
let f = j::execute_async(
64-
QUERY,
81+
ASYNC_QUERY,
6582
vec![("ids".to_string(), ids.clone())].into_iter().collect(),
6683
);
6784
rt.block_on(f)
@@ -70,5 +87,5 @@ fn bench_sync_vs_async_single_user_flat_instant(c: &mut Criterion) {
7087
);
7188
}
7289

73-
criterion_group!(benches, bench_sync_vs_async_single_user_flat_instant);
90+
criterion_group!(benches, bench_sync_vs_async_users_flat_instant);
7491
criterion_main!(benches);

juniper_benchmarks/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ pub fn execute(query: &str, vars: Variables) -> QueryResult {
105105
juniper::execute(query, None, &root, &vars, &ctx).map_err(|e| format!("{:?}", e))
106106
}
107107

108-
#[cfg(feature = "async")]
109108
pub async fn execute_async(query: &str, vars: Variables) -> QueryResult {
110109
let root = new_schema();
111110
let ctx = Context::new();

juniper_codegen/src/util/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ impl GraphQLTypeDefiniton {
930930
) -> #juniper_crate_name::BoxFuture<'b, #juniper_crate_name::ExecutionResult<#scalar>>
931931
where #scalar: Send + Sync,
932932
{
933-
//use futures::future;
933+
use futures::future;
934934
use #juniper_crate_name::GraphQLType;
935935
match field {
936936
#( #resolve_matches_async )*

juniper_rocket_async/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ juniper = { version = "0.14.1", default-features = false, path = "../juniper"}
2222

2323
futures = { version = "=0.3.1", features = ["compat"] }
2424
rocket = { git = "https://github.com/SergioBenitez/Rocket", branch = "async" }
25-
tokio = "=0.2.0-alpha.6"
25+
tokio = "0.2"
2626

2727
[dev-dependencies.juniper]
2828
version = "0.14.1"

0 commit comments

Comments
 (0)