Skip to content
Snippets Groups Projects
Commit b427bbb3 authored by Bastian Köcher's avatar Bastian Köcher Committed by GitHub
Browse files

Make `run_node_until_exit` take a future (#7318)

The function takes a closure that resolved before to a `TaskManager`,
now it resolves to a `Future` which output is a `TaskManager`. This is
required for node setups that are async.
parent bcde7b4f
No related merge requests found
......@@ -126,9 +126,11 @@ pub fn run() -> sc_cli::Result<()> {
},
None => {
let runner = cli.create_runner(&cli.run)?;
runner.run_node_until_exit(|config| match config.role {
Role::Light => service::new_light(config),
_ => service::new_full(config),
runner.run_node_until_exit(|config| async move {
match config.role {
Role::Light => service::new_light(config),
_ => service::new_full(config),
}
})
}
}
......
......@@ -72,9 +72,11 @@ pub fn run() -> Result<()> {
match &cli.subcommand {
None => {
let runner = cli.create_runner(&cli.run)?;
runner.run_node_until_exit(|config| match config.role {
Role::Light => service::new_light(config),
_ => service::new_full(config),
runner.run_node_until_exit(|config| async move {
match config.role {
Role::Light => service::new_light(config),
_ => service::new_full(config),
}
})
}
Some(Subcommand::Inspect(cmd)) => {
......
......@@ -172,24 +172,24 @@ impl<C: SubstrateCli> Runner<C> {
/// A helper function that runs a node with tokio and stops if the process receives the signal
/// `SIGTERM` or `SIGINT`.
pub fn run_node_until_exit(
pub fn run_node_until_exit<F: Future<Output = sc_service::error::Result<TaskManager>>>(
mut self,
initialise: impl FnOnce(Configuration) -> sc_service::error::Result<TaskManager>,
initialize: impl FnOnce(Configuration) -> F,
) -> Result<()> {
self.print_node_infos();
let mut task_manager = initialise(self.config)?;
let mut task_manager = self.tokio_runtime.block_on(initialize(self.config))?;
let res = self.tokio_runtime.block_on(main(task_manager.future().fuse()));
self.tokio_runtime.block_on(task_manager.clean_shutdown());
res.map_err(|e| e.to_string().into())
}
/// A helper function that runs a command with the configuration of this node
/// A helper function that runs a command with the configuration of this node.
pub fn sync_run(self, runner: impl FnOnce(Configuration) -> Result<()>) -> Result<()> {
runner(self.config)
}
/// A helper function that runs a future with tokio and stops if the process receives
/// the signal SIGTERM or SIGINT
/// the signal `SIGTERM` or `SIGINT`.
pub fn async_run<FUT>(
self, runner: impl FnOnce(Configuration) -> Result<(FUT, TaskManager)>,
) -> Result<()>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment