From 1146d9cf30eb32b74f2e87db582c5cdc89ff4d7a Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Thu, 14 Mar 2019 20:48:58 -0700 Subject: [PATCH] fix init order --- actix-server/src/config.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/actix-server/src/config.rs b/actix-server/src/config.rs index 62b9e2a6..a861ad9b 100644 --- a/actix-server/src/config.rs +++ b/actix-server/src/config.rs @@ -114,19 +114,23 @@ impl InternalServiceFactory for ConfiguredService { self.rt.configure(&mut rt); rt.validate(); - // construct services - let mut fut = Vec::new(); - for (token, ns) in rt.services { - let config = ServerConfig::new(self.names[&token].1); - fut.push(ns.new_service(&config).map(move |service| (token, service))); - } + let services = rt.services; // on start futures if rt.onstart.is_empty() { + // construct services + let mut fut = Vec::new(); + for (token, ns) in services { + let config = ServerConfig::new(self.names[&token].1); + fut.push(ns.new_service(&config).map(move |service| (token, service))); + } + Box::new(join_all(fut).map_err(|e| { error!("Can not construct service: {:?}", e); })) } else { + let names = self.names.clone(); + // run onstart future and then construct services Box::new( join_all(rt.onstart) @@ -134,6 +138,14 @@ impl InternalServiceFactory for ConfiguredService { error!("Can not construct service: {:?}", e); }) .and_then(move |_| { + // construct services + let mut fut = Vec::new(); + for (token, ns) in services { + let config = ServerConfig::new(names[&token].1); + fut.push( + ns.new_service(&config).map(move |service| (token, service)), + ); + } join_all(fut).map_err(|e| { error!("Can not construct service: {:?}", e); })