pub async fn start<T, F, Err>(req: HttpRequest, factory: F) -> Result<HttpResponse, Err>
where
    T: ServiceFactory<Frame, WsSink, Response = Option<Message>> + 'static,
    T::Error: fmt::Debug,
    F: IntoServiceFactory<T, Frame, WsSink>,
    Err: From<T::InitError> + From<HandshakeError>,
{
    let inner_factory = factory.into_factory().map_err(WsError::Service);

    let factory = fn_factory_with_config(move |sink: WsSink| {
        let fut = inner_factory.new_service(sink.clone());

        async move {
            let srv = fut.await?;
            Ok::<_, T::InitError>(apply_fn(srv, move |req, srv| match req {
                DispatchItem::Item(item) => {
                    let s = if matches!(item, Frame::Close(_)) {
                        Some(sink.clone())
                    } else {
                        None
                    };
                    let fut = srv.call(item);
                    Either::Left(async move {
                        let result = fut.await;
                        if let Some(s) = s {
                            rt::spawn(async move { s.io().close() });
                        }
                        result
                    })
                }
                DispatchItem::WBackPressureEnabled
                | DispatchItem::WBackPressureDisabled => Either::Right(Ready::Ok(None)),
                DispatchItem::KeepAliveTimeout => {
                    Either::Right(Ready::Err(WsError::KeepAlive))
                }
                DispatchItem::DecoderError(e) | DispatchItem::EncoderError(e) => {
                    Either::Right(Ready::Err(WsError::Protocol(e)))
                }
                DispatchItem::Disconnect(e) => {
                    Either::Right(Ready::Err(WsError::Disconnected(e)))
                }
            }))
        }
    });

    start_with(req, factory).await
}
/// Do websocket handshake and start websockets service.
Do websocket handshake and start websockets service.
Do websocket handshake and start websockets service .
pub async fn start<T, F, Err>(req: HttpRequest, factory: F) -> Result<HttpResponse, Err>
where
    T: ServiceFactory<Frame, WsSink, Response = Option<Message>> + 'static,
    T::Error: fmt::Debug,
    F: IntoServiceFactory<T, Frame, WsSink>,
    Err: From<T::InitError> + From<HandshakeError>,
{
    let inner_factory = factory.into_factory().map_err(WsError::Service);
    let factory = fn_factory_with_config(move |sink: WsSink| {
        let fut = inner_factory.new_service(sink.clone());
        async move {
            let srv = fut.await?;
            Ok::<_, T::InitError>(apply_fn(srv, move |req, srv| match req {
                DispatchItem::Item(item) => {
                    let s = if matches!(item, Frame::Close(_)) {
                        Some(sink.clone())
                    } else {
                        None
                    };
                    let fut = srv.call(item);
                    Either::Left(async move {
                        let result = fut.await;
                        if let Some(s) = s {
                            rt::spawn(async move { s.io().close() });
                        }
                        result
                    })
                }
                DispatchItem::WBackPressureEnabled
                | DispatchItem::WBackPressureDisabled => Either::Right(Ready::Ok(None)),
                DispatchItem::KeepAliveTimeout => {
                    Either::Right(Ready::Err(WsError::KeepAlive))
                }
                DispatchItem::DecoderError(e) | DispatchItem::EncoderError(e) => {
                    Either::Right(Ready::Err(WsError::Protocol(e)))
                }
                DispatchItem::Disconnect(e) => {
                    Either::Right(Ready::Err(WsError::Disconnected(e)))
                }
            }))
        }
    });
    start_with(req, factory).await
}
pub async fn start < T , F , Err > ( req : HttpRequest , factory : F ) -> Result < HttpResponse , Err > where T : ServiceFactory < Frame , WsSink , Response = Option < Message > > + ' static , T :: Error : fmt :: Debug , F : IntoServiceFactory < T , Frame , WsSink > , Err : From < T :: InitError > + From < HandshakeError > , { let inner_factory = factory . into_factory ( ) . map_err ( WsError :: Service ) ; let factory = fn_factory_with_config ( move | sink : WsSink | { let fut = inner_factory . new_service ( sink . clone ( ) ) ; async move { let srv = fut . await ? ; Ok :: < _ , T :: InitError > ( apply_fn ( srv , move | req , srv | match req { DispatchItem :: Item ( item ) => { let s = if matches ! ( item Frame Close ( ) ) { Some ( sink . clone ( ) ) } else { None } ; let fut = srv . call ( item ) ; Either :: Left ( async move { let result = fut . await ; if let Some ( s ) = s { rt :: spawn ( async move { s . io ( ) . close ( ) } ) ; } result } ) } DispatchItem :: WBackPressureEnabled | DispatchItem :: WBackPressureDisabled => Either :: Right ( Ready :: Ok ( None ) ) , DispatchItem :: KeepAliveTimeout => { Either :: Right ( Ready :: Err ( WsError :: KeepAlive ) ) } DispatchItem :: DecoderError ( e ) | DispatchItem :: EncoderError ( e ) => { Either :: Right ( Ready :: Err ( WsError :: Protocol ( e ) ) ) } DispatchItem :: Disconnect ( e ) => { Either :: Right ( Ready :: Err ( WsError :: Disconnected ( e ) ) ) } } ) ) } } ) ; start_with ( req , factory ) . await }
Do websocket handshake and start websockets service.
Do websocket handshake and start websockets service .
req
HttpRequest
factory
F
req
HttpRequest
factory
F