1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-30 10:32:55 +01:00

added new cancel_future_on_stop

This commit is contained in:
Nikolay Kim 2017-10-30 14:49:20 -07:00
parent e3c058c96e
commit 58de9dcf56
4 changed files with 11 additions and 6 deletions

View File

@ -15,7 +15,7 @@ build = "build.rs"
[badges] [badges]
travis-ci = { repository = "actix/actix-web", branch = "master" } travis-ci = { repository = "actix/actix-web", branch = "master" }
appveyor = { repository = "fafhrd91/actix-web-hdy9d" } appveyor = { repository = "actix/actix-web" }
codecov = { repository = "actix/actix-web", branch = "master", service = "github" } codecov = { repository = "actix/actix-web", branch = "master", service = "github" }
[lib] [lib]

View File

@ -110,7 +110,6 @@ fn main() {
.route_handler("/", StaticFiles::new("examples/static/", true))) .route_handler("/", StaticFiles::new("examples/static/", true)))
.serve::<_, ()>("127.0.0.1:8080").unwrap(); .serve::<_, ()>("127.0.0.1:8080").unwrap();
println!("Started http server: 127.0.0.1:8080");
Arbiter::system().send(msgs::SystemExit(0)); Arbiter::system().send(msgs::SystemExit(0));
let _ = sys.run(); let _ = sys.run();
} }

View File

@ -211,10 +211,10 @@ fn main() {
// redirect to websocket.html // redirect to websocket.html
.resource("/", |r| .resource("/", |r|
r.handler(Method::GET, |req, payload, state| { r.handler(Method::GET, |req, payload, state| {
httpcodes::HTTPFound Ok(httpcodes::HTTPFound
.builder() .builder()
.header("LOCATION", "/static/websocket.html") .header("LOCATION", "/static/websocket.html")
.body(Body::Empty) .body(Body::Empty)?)
})) }))
// websocket // websocket
.resource("/ws/", |r| r.get::<WsChatSession>()) .resource("/ws/", |r| r.get::<WsChatSession>())

View File

@ -35,6 +35,7 @@ pub struct HttpContext<A> where A: Actor<Context=HttpContext<A>> + Route,
impl<A> IoContext for HttpContext<A> where A: Actor<Context=Self> + Route { impl<A> IoContext for HttpContext<A> where A: Actor<Context=Self> + Route {
fn disconnected(&mut self) { fn disconnected(&mut self) {
self.items.stop();
self.disconnected = true; self.disconnected = true;
if self.state == ActorState::Running { if self.state == ActorState::Running {
self.state = ActorState::Stopping; self.state = ActorState::Stopping;
@ -46,6 +47,7 @@ impl<A> ActorContext for HttpContext<A> where A: Actor<Context=Self> + Route
{ {
/// Stop actor execution /// Stop actor execution
fn stop(&mut self) { fn stop(&mut self) {
self.items.stop();
self.address.close(); self.address.close();
if self.state == ActorState::Running { if self.state == ActorState::Running {
self.state = ActorState::Stopping; self.state = ActorState::Stopping;
@ -85,6 +87,10 @@ impl<A> AsyncContext<A> for HttpContext<A> where A: Actor<Context=Self> + Route
self.modified = true; self.modified = true;
self.items.cancel_future(handle) self.items.cancel_future(handle)
} }
fn cancel_future_on_stop(&mut self, handle: SpawnHandle) {
self.items.cancel_future_on_stop(handle)
}
} }
#[doc(hidden)] #[doc(hidden)]