Properly start api server

This commit is contained in:
Gregor Reitzenstein 2020-12-16 12:24:19 +01:00
parent 2fbef020a3
commit be73385758

View File

@ -168,15 +168,17 @@ fn maybe(matches: clap::ArgMatches, log: Arc<Logger>) -> Result<(), Error> {
} }
let (signal, shutdown) = async_channel::bounded::<()>(1); let (signal, shutdown) = async_channel::bounded::<()>(1);
easy_parallel::Parallel::new() let (_, r) = easy_parallel::Parallel::new()
.each(0..4, |_| smol::block_on(ex.run(shutdown.recv()))) .each(0..4, |_| smol::block_on(ex.run(shutdown.recv())))
.run(); .finish(|| {
let db = db::Databases::new(&log, &config)?; let db = db::Databases::new(&log, &config)?;
// TODO: Spawn api connections on their own (non-main) thread, use the main thread to // TODO: Spawn api connections on their own (non-main) thread, use the main thread to
// handle signals (a cli if stdin is not closed?) and make it stop and clean up all threads // handle signals (a cli if stdin is not closed?) and make it stop and clean up all threads
// when bffh should exit // when bffh should exit
server::serve_api_connections(log.clone(), config, db, network) server::serve_api_connections(log.clone(), config, db, network)
// Signal is dropped here, stopping all executor threads as well. // Signal is dropped here, stopping all executor threads as well.
});
return r;
} }
} }