Use async Mutex
in juniper_actix
to fix latest nightly errors
This commit is contained in:
parent
a8759b0a30
commit
168114fcf0
3 changed files with 11 additions and 10 deletions
|
@ -78,6 +78,7 @@ pub struct Human {
|
||||||
name: String,
|
name: String,
|
||||||
friend_ids: Vec<String>,
|
friend_ids: Vec<String>,
|
||||||
appears_in: Vec<Episode>,
|
appears_in: Vec<Episode>,
|
||||||
|
#[allow(dead_code)]
|
||||||
secret_backstory: Option<String>,
|
secret_backstory: Option<String>,
|
||||||
home_planet: Option<String>,
|
home_planet: Option<String>,
|
||||||
}
|
}
|
||||||
|
@ -164,6 +165,7 @@ pub struct Droid {
|
||||||
name: String,
|
name: String,
|
||||||
friend_ids: Vec<String>,
|
friend_ids: Vec<String>,
|
||||||
appears_in: Vec<Episode>,
|
appears_in: Vec<Episode>,
|
||||||
|
#[allow(dead_code)]
|
||||||
secret_backstory: Option<String>,
|
secret_backstory: Option<String>,
|
||||||
primary_function: Option<String>,
|
primary_function: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ documentation = "https://docs.rs/juniper_actix"
|
||||||
repository = "https://github.com/graphql-rust/juniper"
|
repository = "https://github.com/graphql-rust/juniper"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
subscriptions = ["juniper_graphql_ws"]
|
subscriptions = ["juniper_graphql_ws", "tokio"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix = "0.12"
|
actix = "0.12"
|
||||||
|
@ -26,12 +26,13 @@ futures = "0.3"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
|
tokio = { version = "1.0", features = ["sync"], optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix-rt = "2"
|
actix-rt = "2"
|
||||||
actix-cors = "0.6.0-beta.2"
|
actix-cors = "0.6.0-beta.2"
|
||||||
actix-identity = "0.4.0-beta.2"
|
actix-identity = "0.4.0-beta.2"
|
||||||
tokio = "1"
|
tokio = "1.0"
|
||||||
async-stream = "0.3"
|
async-stream = "0.3"
|
||||||
actix-test = "0.1.0-beta.3"
|
actix-test = "0.1.0-beta.3"
|
||||||
|
|
||||||
|
|
|
@ -211,10 +211,7 @@ pub async fn playground_handler(
|
||||||
/// [1]: https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md
|
/// [1]: https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md
|
||||||
#[cfg(feature = "subscriptions")]
|
#[cfg(feature = "subscriptions")]
|
||||||
pub mod subscriptions {
|
pub mod subscriptions {
|
||||||
use std::{
|
use std::{fmt, sync::Arc};
|
||||||
fmt,
|
|
||||||
sync::{Arc, Mutex},
|
|
||||||
};
|
|
||||||
|
|
||||||
use actix::{prelude::*, Actor, StreamHandler};
|
use actix::{prelude::*, Actor, StreamHandler};
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
|
@ -222,7 +219,6 @@ pub mod subscriptions {
|
||||||
web, HttpRequest, HttpResponse,
|
web, HttpRequest, HttpResponse,
|
||||||
};
|
};
|
||||||
use actix_web_actors::ws;
|
use actix_web_actors::ws;
|
||||||
|
|
||||||
use juniper::{
|
use juniper::{
|
||||||
futures::{
|
futures::{
|
||||||
stream::{SplitSink, SplitStream, StreamExt},
|
stream::{SplitSink, SplitStream, StreamExt},
|
||||||
|
@ -231,6 +227,7 @@ pub mod subscriptions {
|
||||||
GraphQLSubscriptionType, GraphQLTypeAsync, RootNode, ScalarValue,
|
GraphQLSubscriptionType, GraphQLTypeAsync, RootNode, ScalarValue,
|
||||||
};
|
};
|
||||||
use juniper_graphql_ws::{ArcSchema, ClientMessage, Connection, Init, ServerMessage};
|
use juniper_graphql_ws::{ArcSchema, ClientMessage, Connection, Init, ServerMessage};
|
||||||
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
/// Serves the graphql-ws protocol over a WebSocket connection.
|
/// Serves the graphql-ws protocol over a WebSocket connection.
|
||||||
///
|
///
|
||||||
|
@ -326,8 +323,9 @@ pub mod subscriptions {
|
||||||
let tx = self.graphql_tx.clone();
|
let tx = self.graphql_tx.clone();
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
let mut tx = tx.lock().unwrap();
|
tx.lock()
|
||||||
tx.send(msg)
|
.await
|
||||||
|
.send(msg)
|
||||||
.await
|
.await
|
||||||
.expect("Infallible: this should not happen");
|
.expect("Infallible: this should not happen");
|
||||||
}
|
}
|
||||||
|
@ -363,7 +361,7 @@ pub mod subscriptions {
|
||||||
let addr = ctx.address();
|
let addr = ctx.address();
|
||||||
|
|
||||||
let fut = async move {
|
let fut = async move {
|
||||||
let mut stream = stream.lock().unwrap();
|
let mut stream = stream.lock().await;
|
||||||
while let Some(message) = stream.next().await {
|
while let Some(message) = stream.next().await {
|
||||||
// sending the message to self so that it can be forwarded back to the client
|
// sending the message to self so that it can be forwarded back to the client
|
||||||
addr.do_send(ServerMessageWrapper { message });
|
addr.do_send(ServerMessageWrapper { message });
|
||||||
|
|
Loading…
Reference in a new issue