1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-28 09:42:40 +01:00

add 0.5 sec deley before exit

This commit is contained in:
Nikolay Kim 2018-03-22 18:41:02 -07:00
parent 5a25fd95f5
commit 449709dd7e

View File

@ -630,19 +630,22 @@ impl<H: IntoHttpHandler> Handler<StopServer> for HttpServer<H>
}; };
for worker in &self.workers { for worker in &self.workers {
let tx2 = tx.clone(); let tx2 = tx.clone();
let fut = worker.1.send(StopWorker{graceful: dur}).into_actor(self); worker.1.send(StopWorker{graceful: dur})
ActorFuture::then(fut, move |_, slf, _| { .into_actor(self)
slf.workers.pop(); .then(move |_, slf, ctx| {
if slf.workers.is_empty() { slf.workers.pop();
let _ = tx2.send(()); if slf.workers.is_empty() {
let _ = tx2.send(());
// we need to stop system if server was spawned // we need to stop system if server was spawned
if slf.exit { if slf.exit {
Arbiter::system().do_send(actix::msgs::SystemExit(0)) ctx.run_later(Duration::from_millis(500), |_, _| {
Arbiter::system().do_send(actix::msgs::SystemExit(0))
});
}
} }
} actix::fut::ok(())
actix::fut::ok(()) }).spawn(ctx);
}).spawn(ctx);
} }
if !self.workers.is_empty() { if !self.workers.is_empty() {
@ -651,7 +654,9 @@ impl<H: IntoHttpHandler> Handler<StopServer> for HttpServer<H>
} else { } else {
// we need to stop system if server was spawned // we need to stop system if server was spawned
if self.exit { if self.exit {
Arbiter::system().do_send(actix::msgs::SystemExit(0)) ctx.run_later(Duration::from_millis(500), |_, _| {
Arbiter::system().do_send(actix::msgs::SystemExit(0))
});
} }
Response::reply(Ok(())) Response::reply(Ok(()))
} }