Skip to content
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

Refactor code to remove async move closure which may result in double… #1256

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
42 changes: 20 additions & 22 deletions juniper/src/types/async_await.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,31 +258,29 @@ where
let is_non_null = meta_field.field_type.is_non_null();

let response_name = response_name.to_string();
async_values.push_back(AsyncValueFuture::Field(async move {
// TODO: implement custom future type instead of
// two-level boxing.
Comment on lines -262 to -263
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any boxing at all.. AsyncValueFuture is generic so this comment looks outdated.

let res = instance
.resolve_field_async(info, f.name.item, &args, &sub_exec)
.await;

let value = match res {
Ok(Value::Null) if is_non_null => None,
Ok(v) => Some(v),
Err(e) => {
sub_exec.push_error_at(e, pos);

if is_non_null {
None
} else {
Some(Value::null())
}
let res = instance
.resolve_field_async(info, f.name.item, &args, &sub_exec)
.await;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this .await breaks concurrency. The await now happens directly within the for loop body, so the future will pause at this point before processing the next select. The intention of async_values is that the loop should produce all the futures synchronously up front, then after this loop there is another while loop at the bottom of the function which polls the FuturesOrdered so that all its contained futures may progress simultaneously.


let value = match res {
Ok(Value::Null) if is_non_null => None,
Ok(v) => Some(v),
Err(e) => {
sub_exec.push_error_at(e, pos);
if is_non_null {
None
} else {
Some(Value::null())
}
};
AsyncValue::Field(AsyncField {
}
};

async_values.push_back(AsyncValueFuture::Field(future::ready(AsyncValue::Field(
AsyncField {
name: response_name,
value,
})
}));
},
))));
}

Selection::FragmentSpread(Spanning {
Expand Down