@@ -211,18 +211,14 @@ pub async fn playground_handler(
211211/// [1]: https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md
212212#[ cfg( feature = "subscriptions" ) ]
213213pub mod subscriptions {
214- use std:: {
215- fmt,
216- sync:: { Arc , Mutex } ,
217- } ;
214+ use std:: { fmt, sync:: Arc } ;
218215
219216 use actix:: { prelude:: * , Actor , StreamHandler } ;
220217 use actix_web:: {
221218 http:: header:: { HeaderName , HeaderValue } ,
222219 web, HttpRequest , HttpResponse ,
223220 } ;
224221 use actix_web_actors:: ws;
225-
226222 use juniper:: {
227223 futures:: {
228224 stream:: { SplitSink , SplitStream , StreamExt } ,
@@ -231,6 +227,7 @@ pub mod subscriptions {
231227 GraphQLSubscriptionType , GraphQLTypeAsync , RootNode , ScalarValue ,
232228 } ;
233229 use juniper_graphql_ws:: { ArcSchema , ClientMessage , Connection , Init , ServerMessage } ;
230+ use tokio:: sync:: Mutex ;
234231
235232 /// Serves the graphql-ws protocol over a WebSocket connection.
236233 ///
@@ -326,8 +323,9 @@ pub mod subscriptions {
326323 let tx = self . graphql_tx . clone ( ) ;
327324
328325 async move {
329- let mut tx = tx. lock ( ) . unwrap ( ) ;
330- tx. send ( msg)
326+ tx. lock ( )
327+ . await
328+ . send ( msg)
331329 . await
332330 . expect ( "Infallible: this should not happen" ) ;
333331 }
@@ -363,7 +361,7 @@ pub mod subscriptions {
363361 let addr = ctx. address ( ) ;
364362
365363 let fut = async move {
366- let mut stream = stream. lock ( ) . unwrap ( ) ;
364+ let mut stream = stream. lock ( ) . await ;
367365 while let Some ( message) = stream. next ( ) . await {
368366 // sending the message to self so that it can be forwarded back to the client
369367 addr. do_send ( ServerMessageWrapper { message } ) ;
0 commit comments