Update to latest tokio
This commit is contained in:
parent
d22fab76c8
commit
c42c71b02d
9 changed files with 49 additions and 50 deletions
|
@ -10,4 +10,4 @@ async = []
|
|||
[dependencies]
|
||||
juniper = { path = "../../juniper", features = ["async"] }
|
||||
futures = "=0.3.1"
|
||||
tokio = "=0.2.0-alpha.6"
|
||||
tokio = { version = "0.2", features = ["rt-core", "time", "macros"] }
|
|
@ -34,8 +34,7 @@ impl User {
|
|||
}
|
||||
|
||||
async fn delayed() -> bool {
|
||||
let when = tokio::clock::now() + std::time::Duration::from_millis(100);
|
||||
tokio::timer::delay(when).await;
|
||||
tokio::time::delay_for(std::time::Duration::from_millis(100)).await;
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -61,8 +60,7 @@ impl Query {
|
|||
}
|
||||
|
||||
async fn delayed() -> bool {
|
||||
let when = tokio::clock::now() + std::time::Duration::from_millis(100);
|
||||
tokio::timer::delay(when).await;
|
||||
tokio::time::delay_for(std::time::Duration::from_millis(100)).await;
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -72,14 +70,8 @@ struct Mutation;
|
|||
#[juniper::graphql_object]
|
||||
impl Mutation {}
|
||||
|
||||
fn run<O>(f: impl std::future::Future<Output = O>) -> O {
|
||||
tokio::runtime::current_thread::Runtime::new()
|
||||
.unwrap()
|
||||
.block_on(f)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn async_simple() {
|
||||
#[tokio::test]
|
||||
async fn async_simple() {
|
||||
let schema = RootNode::new(Query, Mutation);
|
||||
let doc = r#"
|
||||
query {
|
||||
|
@ -95,9 +87,9 @@ fn async_simple() {
|
|||
"#;
|
||||
|
||||
let vars = Default::default();
|
||||
let f = juniper::execute_async(doc, None, &schema, &vars, &());
|
||||
|
||||
let (res, errs) = run(f).unwrap();
|
||||
let (res, errs) = juniper::execute_async(doc, None, &schema, &vars, &())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(errs.is_empty());
|
||||
|
||||
|
|
|
@ -48,4 +48,4 @@ uuid = { version = ">= 0.7, < 0.8", optional = true }
|
|||
[dev-dependencies]
|
||||
bencher = "0.1.2"
|
||||
serde_json = { version = "1.0.2" }
|
||||
tokio = "=0.2.0-alpha.6"
|
||||
tokio = { version = "0.2", features = ["macros", "rt-core", "time"] }
|
||||
|
|
|
@ -35,8 +35,7 @@ impl User {
|
|||
}
|
||||
|
||||
async fn delayed() -> bool {
|
||||
let when = tokio::clock::now() + std::time::Duration::from_millis(100);
|
||||
tokio::timer::delay(when).await;
|
||||
tokio::time::delay_for(std::time::Duration::from_millis(100)).await;
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -62,8 +61,7 @@ impl Query {
|
|||
}
|
||||
|
||||
async fn delayed() -> bool {
|
||||
let when = tokio::clock::now() + std::time::Duration::from_millis(100);
|
||||
tokio::timer::delay(when).await;
|
||||
tokio::time::delay_for(std::time::Duration::from_millis(100)).await;
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -73,14 +71,8 @@ struct Mutation;
|
|||
#[crate::graphql_object_internal]
|
||||
impl Mutation {}
|
||||
|
||||
fn run<O>(f: impl std::future::Future<Output = O>) -> O {
|
||||
tokio::runtime::current_thread::Runtime::new()
|
||||
.unwrap()
|
||||
.block_on(f)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn async_simple() {
|
||||
#[tokio::test]
|
||||
async fn async_simple() {
|
||||
let schema = RootNode::new(Query, Mutation);
|
||||
let doc = r#"
|
||||
query {
|
||||
|
@ -94,9 +86,9 @@ fn async_simple() {
|
|||
"#;
|
||||
|
||||
let vars = Default::default();
|
||||
let f = crate::execute_async(doc, None, &schema, &vars, &());
|
||||
|
||||
let (res, errs) = run(f).unwrap();
|
||||
let (res, errs) = crate::execute_async(doc, None, &schema, &vars, &())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(errs.is_empty());
|
||||
|
||||
|
|
|
@ -5,18 +5,17 @@ authors = ["Christoph Herzog <chris@theduke.at>"]
|
|||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[[bench]]
|
||||
name = "benchmark"
|
||||
harness = false
|
||||
|
||||
[features]
|
||||
async = ["juniper/async", "futures"]
|
||||
async = []
|
||||
|
||||
[dependencies]
|
||||
juniper = { path = "../juniper" }
|
||||
futures = { version = "=0.3.1", optional = true }
|
||||
juniper = { path = "../juniper", features = ["async"] }
|
||||
futures = "=0.3.1"
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = "0.2.11"
|
||||
tokio = "=0.2.0-alpha.6"
|
||||
tokio = { version = "0.2.0", features = ["rt-threaded", "rt-core"] }
|
||||
|
|
|
@ -5,10 +5,10 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion, Parameter
|
|||
use juniper::{graphql_value, InputValue, ToInputValue, Value};
|
||||
use juniper_benchmarks as j;
|
||||
|
||||
fn bench_sync_vs_async_single_user_flat_instant(c: &mut Criterion) {
|
||||
const QUERY: &'static str = r#"
|
||||
fn bench_sync_vs_async_users_flat_instant(c: &mut Criterion) {
|
||||
const ASYNC_QUERY: &'static str = r#"
|
||||
query Query($id: Int) {
|
||||
user(id: $id) {
|
||||
users_async_instant(ids: [$id]!) {
|
||||
id
|
||||
kind
|
||||
username
|
||||
|
@ -17,8 +17,19 @@ fn bench_sync_vs_async_single_user_flat_instant(c: &mut Criterion) {
|
|||
}
|
||||
"#;
|
||||
|
||||
const SYNC_QUERY: &'static str = r#"
|
||||
query Query($id: Int) {
|
||||
users_sync_instant(ids: [$id]!) {
|
||||
id
|
||||
kind
|
||||
username
|
||||
email
|
||||
}
|
||||
}
|
||||
"#;
|
||||
|
||||
c.bench(
|
||||
"Sync vs Async - Single User Flat - Instant",
|
||||
"Sync vs Async - Users Flat - Instant",
|
||||
ParameterizedBenchmark::new(
|
||||
"Sync",
|
||||
|b, count| {
|
||||
|
@ -28,7 +39,7 @@ fn bench_sync_vs_async_single_user_flat_instant(c: &mut Criterion) {
|
|||
let ids = InputValue::list(ids);
|
||||
b.iter(|| {
|
||||
j::execute(
|
||||
QUERY,
|
||||
SYNC_QUERY,
|
||||
vec![("ids".to_string(), ids.clone())].into_iter().collect(),
|
||||
)
|
||||
})
|
||||
|
@ -36,7 +47,10 @@ fn bench_sync_vs_async_single_user_flat_instant(c: &mut Criterion) {
|
|||
vec![1, 10],
|
||||
)
|
||||
.with_function("Async - Single Thread", |b, count| {
|
||||
let mut rt = tokio::runtime::current_thread::Runtime::new().unwrap();
|
||||
let mut rt = tokio::runtime::Builder::new()
|
||||
.basic_scheduler()
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let ids = (0..*count)
|
||||
.map(|x| InputValue::scalar(x as i32))
|
||||
|
@ -45,14 +59,17 @@ fn bench_sync_vs_async_single_user_flat_instant(c: &mut Criterion) {
|
|||
|
||||
b.iter(|| {
|
||||
let f = j::execute_async(
|
||||
QUERY,
|
||||
ASYNC_QUERY,
|
||||
vec![("ids".to_string(), ids.clone())].into_iter().collect(),
|
||||
);
|
||||
rt.block_on(f)
|
||||
})
|
||||
})
|
||||
.with_function("Async - Threadpool", |b, count| {
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
let mut rt = tokio::runtime::Builder::new()
|
||||
.threaded_scheduler()
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let ids = (0..*count)
|
||||
.map(|x| InputValue::scalar(x as i32))
|
||||
|
@ -61,7 +78,7 @@ fn bench_sync_vs_async_single_user_flat_instant(c: &mut Criterion) {
|
|||
|
||||
b.iter(|| {
|
||||
let f = j::execute_async(
|
||||
QUERY,
|
||||
ASYNC_QUERY,
|
||||
vec![("ids".to_string(), ids.clone())].into_iter().collect(),
|
||||
);
|
||||
rt.block_on(f)
|
||||
|
@ -70,5 +87,5 @@ fn bench_sync_vs_async_single_user_flat_instant(c: &mut Criterion) {
|
|||
);
|
||||
}
|
||||
|
||||
criterion_group!(benches, bench_sync_vs_async_single_user_flat_instant);
|
||||
criterion_group!(benches, bench_sync_vs_async_users_flat_instant);
|
||||
criterion_main!(benches);
|
||||
|
|
|
@ -105,7 +105,6 @@ pub fn execute(query: &str, vars: Variables) -> QueryResult {
|
|||
juniper::execute(query, None, &root, &vars, &ctx).map_err(|e| format!("{:?}", e))
|
||||
}
|
||||
|
||||
#[cfg(feature = "async")]
|
||||
pub async fn execute_async(query: &str, vars: Variables) -> QueryResult {
|
||||
let root = new_schema();
|
||||
let ctx = Context::new();
|
||||
|
|
|
@ -930,7 +930,7 @@ impl GraphQLTypeDefiniton {
|
|||
) -> #juniper_crate_name::BoxFuture<'b, #juniper_crate_name::ExecutionResult<#scalar>>
|
||||
where #scalar: Send + Sync,
|
||||
{
|
||||
//use futures::future;
|
||||
use futures::future;
|
||||
use #juniper_crate_name::GraphQLType;
|
||||
match field {
|
||||
#( #resolve_matches_async )*
|
||||
|
|
|
@ -22,7 +22,7 @@ juniper = { version = "0.14.1", default-features = false, path = "../juniper"}
|
|||
|
||||
futures = { version = "=0.3.1", features = ["compat"] }
|
||||
rocket = { git = "https://github.com/SergioBenitez/Rocket", branch = "async" }
|
||||
tokio = "=0.2.0-alpha.6"
|
||||
tokio = "0.2"
|
||||
|
||||
[dev-dependencies.juniper]
|
||||
version = "0.14.1"
|
||||
|
|
Loading…
Reference in a new issue