1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-06-25 09:59:21 +02:00

refactor reply handling

This commit is contained in:
Nikolay Kim
2017-11-28 19:49:17 -08:00
parent 6f5b58b691
commit afeecea05f
19 changed files with 167 additions and 144 deletions

View File

@ -7,7 +7,6 @@ extern crate env_logger;
extern crate futures;
use actix_web::*;
use actix_web::error::{Error, Result};
use actix_web::middlewares::RequestSession;
use futures::stream::{once, Once};

View File

@ -37,12 +37,12 @@ impl Route for MyWebSocket {
/// Shared application state
type State = AppState;
fn request(mut req: HttpRequest<AppState>, ctx: &mut HttpContext<Self>) -> RouteResult<Self>
fn request(mut req: HttpRequest<AppState>, mut ctx: HttpContext<Self>) -> Result<Reply>
{
let resp = ws::handshake(&req)?;
ctx.start(resp);
ctx.add_stream(ws::WsStream::new(&mut req));
Reply::async(MyWebSocket{counter: 0})
ctx.reply(MyWebSocket{counter: 0})
}
}

View File

@ -22,7 +22,7 @@ impl Actor for MyWebSocket {
impl Route for MyWebSocket {
type State = ();
fn request(mut req: HttpRequest, ctx: &mut HttpContext<Self>) -> RouteResult<Self>
fn request(mut req: HttpRequest, mut ctx: HttpContext<Self>) -> Result<Reply>
{
// websocket handshake
let resp = ws::handshake(&req)?;
@ -30,7 +30,7 @@ impl Route for MyWebSocket {
ctx.start(resp);
// convert bytes stream to a stream of `ws::Message` and register it
ctx.add_stream(ws::WsStream::new(&mut req));
Reply::async(MyWebSocket)
ctx.reply(MyWebSocket)
}
}