pub async fn subscribe_protocol<T: NashProtocolSubscription + Send + Sync + 'static>(
        &self,
        request: T,
    ) -> Result<
        mpsc::UnboundedReceiver<
            Result<ResponseOrError<<T as NashProtocolSubscription>::SubscriptionResponse>>,
        >,
    > {
        let query = request.graphql(self.state.clone()).await?;
        // a subscription starts with a normal request
        let subscription_response = self
            .request(query)
            .await?
            .await
            .map_err(|_| ProtocolError("Could not get subscription response"))??;
        // create a channel where associated data will be pushed back
        let (for_broker, callback_channel) = mpsc::unbounded_channel();
        let broker_link = self.ws_state.message_broker.link.clone();
        // use subscription id on the response we got back from the subscription query
        // to register incoming data with the broker
        let subscription_id = subscription_response
            .subscription_setup_id()
            .ok_or(ProtocolError("Response does not include subscription id"))?;
        broker_link
            .send(BrokerAction::RegisterSubscription(
                subscription_id,
                for_broker,
            ))
            .map_err(|_| ProtocolError("Could not register subscription with broker"))?;

        let (user_callback_sender, user_callback_receiver) = mpsc::unbounded_channel();

        global_subscription_loop(
            callback_channel,
            user_callback_sender,
            self.ws_state.global_subscription_sender.clone(),
            request.clone(),
            self.state.clone(),
        );

        Ok(user_callback_receiver)
    }
/// Entry point for running Nash protocol subscriptions
Entry point for running Nash protocol subscriptions
Entry point for running Nash protocol subscriptions
pub async fn subscribe_protocol<T: NashProtocolSubscription + Send + Sync + 'static>(
        &self,
        request: T,
    ) -> Result<
        mpsc::UnboundedReceiver<
            Result<ResponseOrError<<T as NashProtocolSubscription>::SubscriptionResponse>>,
        >,
    > {
        let query = request.graphql(self.state.clone()).await?;
        // a subscription starts with a normal request
        let subscription_response = self
            .request(query)
            .await?
            .await
            .map_err(|_| ProtocolError("Could not get subscription response"))??;
        // create a channel where associated data will be pushed back
        let (for_broker, callback_channel) = mpsc::unbounded_channel();
        let broker_link = self.ws_state.message_broker.link.clone();
        // use subscription id on the response we got back from the subscription query
        // to register incoming data with the broker
        let subscription_id = subscription_response
            .subscription_setup_id()
            .ok_or(ProtocolError("Response does not include subscription id"))?;
        broker_link
            .send(BrokerAction::RegisterSubscription(
                subscription_id,
                for_broker,
            ))
            .map_err(|_| ProtocolError("Could not register subscription with broker"))?;
        let (user_callback_sender, user_callback_receiver) = mpsc::unbounded_channel();
        global_subscription_loop(
            callback_channel,
            user_callback_sender,
            self.ws_state.global_subscription_sender.clone(),
            request.clone(),
            self.state.clone(),
        );
        Ok(user_callback_receiver)
    }
pub async fn subscribe_protocol < T : NashProtocolSubscription + Send + Sync + ' static > ( & self , request : T , ) -> Result < mpsc :: UnboundedReceiver < Result < ResponseOrError < < T as NashProtocolSubscription > :: SubscriptionResponse > > , > , > { let query = request . graphql ( self . state . clone ( ) ) . await ? ; // a subscription starts with a normal request let subscription_response = self . request ( query ) . await ? . await . map_err ( | _ | ProtocolError ( " " ) ) ? ? ; // create a channel where associated data will be pushed back let ( for_broker , callback_channel ) = mpsc :: unbounded_channel ( ) ; let broker_link = self . ws_state . message_broker . link . clone ( ) ; // use subscription id on the response we got back from the subscription query // to register incoming data with the broker let subscription_id = subscription_response . subscription_setup_id ( ) . ok_or ( ProtocolError ( " " ) ) ? ; broker_link . send ( BrokerAction :: RegisterSubscription ( subscription_id , for_broker , ) ) . map_err ( | _ | ProtocolError ( " " ) ) ? ; let ( user_callback_sender , user_callback_receiver ) = mpsc :: unbounded_channel ( ) ; global_subscription_loop ( callback_channel , user_callback_sender , self . ws_state . global_subscription_sender . clone ( ) , request . clone ( ) , self . state . clone ( ) , ) ; Ok ( user_callback_receiver ) }
Entry point for running Nash protocol subscriptions
Entry point for running Nash protocol subscriptions
&self
request
T