From 449709dd7e291e6b5612eca85477d2722bfbcc9a Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Thu, 22 Mar 2018 18:41:02 -0700 Subject: [PATCH] add 0.5 sec deley before exit --- src/server/srv.rs | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/server/srv.rs b/src/server/srv.rs index bb065c47e..4bb78b8bb 100644 --- a/src/server/srv.rs +++ b/src/server/srv.rs @@ -630,19 +630,22 @@ impl Handler for HttpServer }; for worker in &self.workers { let tx2 = tx.clone(); - let fut = worker.1.send(StopWorker{graceful: dur}).into_actor(self); - ActorFuture::then(fut, move |_, slf, _| { - slf.workers.pop(); - if slf.workers.is_empty() { - let _ = tx2.send(()); + worker.1.send(StopWorker{graceful: dur}) + .into_actor(self) + .then(move |_, slf, ctx| { + slf.workers.pop(); + if slf.workers.is_empty() { + let _ = tx2.send(()); - // we need to stop system if server was spawned - if slf.exit { - Arbiter::system().do_send(actix::msgs::SystemExit(0)) + // we need to stop system if server was spawned + if slf.exit { + ctx.run_later(Duration::from_millis(500), |_, _| { + Arbiter::system().do_send(actix::msgs::SystemExit(0)) + }); + } } - } - actix::fut::ok(()) - }).spawn(ctx); + actix::fut::ok(()) + }).spawn(ctx); } if !self.workers.is_empty() { @@ -651,7 +654,9 @@ impl Handler for HttpServer } else { // we need to stop system if server was spawned 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(())) }