Skip to content

Commit

Permalink
Make http extension futures Send (#130)
Browse files Browse the repository at this point in the history
#### Why are we making this change?

I just tested out the new SurfExt trait with some of my production code.  I was
having trouble getting it working, as the futures it returns were not Send.
This was mostly because `SerializeError` was not `Send + Sync`.

#### What effects does this change have?

This adds `Send + Sync` constraints to `SerializeError` which allows the
futures in `SurfExt` & `ReqwestExt` to be `Send`.

Possible that the API could have been reworked to do this without updating the
constraints on `SerializeError`, but I'm fairly sure having errors as Send +
Sync is good practice anyway.
  • Loading branch information
obmarg authored Oct 11, 2020
1 parent 6830dab commit 7f11cff
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ all APIs might be changed.
- The `InputObject` derive no longer complains if you omit optional fields.
The old behaviour can be brought back by attaching a `require_all_fields`
annotation to the InputObject.
- SerializeError now requires Send + Sync on it's boxed value.

### New Features

Expand Down
4 changes: 2 additions & 2 deletions cynic/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mod surf_ext {

use crate::{GraphQLResponse, Operation};

type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a>>;
type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;

/// An extension trait for surf::RequestBuilder.
///
Expand Down Expand Up @@ -113,7 +113,7 @@ mod reqwest_ext {

use crate::{GraphQLResponse, Operation};

type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a>>;
type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;

/// An extension trait for reqwest::RequestBuilder.
///
Expand Down
2 changes: 1 addition & 1 deletion cynic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ where
}
}

pub type SerializeError = Box<dyn std::error::Error>;
pub type SerializeError = Box<dyn std::error::Error + Send + Sync>;

/// A trait for GraphQL enums.
///
Expand Down

0 comments on commit 7f11cff

Please sign in to comment.