Use async Mutex in juniper_actix to fix latest nightly errors

This commit is contained in:
tyranron 2021-10-11 19:24:30 +03:00
parent a8759b0a30
commit 168114fcf0
No known key found for this signature in database
GPG key ID: 762E144FB230A4F0
3 changed files with 11 additions and 10 deletions

View file

@ -78,6 +78,7 @@ pub struct Human {
name: String,
friend_ids: Vec<String>,
appears_in: Vec<Episode>,
#[allow(dead_code)]
secret_backstory: Option<String>,
home_planet: Option<String>,
}
@ -164,6 +165,7 @@ pub struct Droid {
name: String,
friend_ids: Vec<String>,
appears_in: Vec<Episode>,
#[allow(dead_code)]
secret_backstory: Option<String>,
primary_function: Option<String>,
}

View file

@ -9,7 +9,7 @@ documentation = "https://docs.rs/juniper_actix"
repository = "https://github.com/graphql-rust/juniper"
[features]
subscriptions = ["juniper_graphql_ws"]
subscriptions = ["juniper_graphql_ws", "tokio"]
[dependencies]
actix = "0.12"
@ -26,12 +26,13 @@ futures = "0.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0"
tokio = { version = "1.0", features = ["sync"], optional = true }
[dev-dependencies]
actix-rt = "2"
actix-cors = "0.6.0-beta.2"
actix-identity = "0.4.0-beta.2"
tokio = "1"
tokio = "1.0"
async-stream = "0.3"
actix-test = "0.1.0-beta.3"

View file

@ -211,10 +211,7 @@ pub async fn playground_handler(
/// [1]: https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md
#[cfg(feature = "subscriptions")]
pub mod subscriptions {
use std::{
fmt,
sync::{Arc, Mutex},
};
use std::{fmt, sync::Arc};
use actix::{prelude::*, Actor, StreamHandler};
use actix_web::{
@ -222,7 +219,6 @@ pub mod subscriptions {
web, HttpRequest, HttpResponse,
};
use actix_web_actors::ws;
use juniper::{
futures::{
stream::{SplitSink, SplitStream, StreamExt},
@ -231,6 +227,7 @@ pub mod subscriptions {
GraphQLSubscriptionType, GraphQLTypeAsync, RootNode, ScalarValue,
};
use juniper_graphql_ws::{ArcSchema, ClientMessage, Connection, Init, ServerMessage};
use tokio::sync::Mutex;
/// Serves the graphql-ws protocol over a WebSocket connection.
///
@ -326,8 +323,9 @@ pub mod subscriptions {
let tx = self.graphql_tx.clone();
async move {
let mut tx = tx.lock().unwrap();
tx.send(msg)
tx.lock()
.await
.send(msg)
.await
.expect("Infallible: this should not happen");
}
@ -363,7 +361,7 @@ pub mod subscriptions {
let addr = ctx.address();
let fut = async move {
let mut stream = stream.lock().unwrap();
let mut stream = stream.lock().await;
while let Some(message) = stream.next().await {
// sending the message to self so that it can be forwarded back to the client
addr.do_send(ServerMessageWrapper { message });