diff --git a/substrate/core/cli/src/informant.rs b/substrate/core/cli/src/informant.rs index dd0237b7f8..5c60229fab 100644 --- a/substrate/core/cli/src/informant.rs +++ b/substrate/core/cli/src/informant.rs @@ -32,9 +32,16 @@ use runtime_primitives::generic::BlockId; use runtime_primitives::traits::{Header, SaturatedConversion}; /// Spawn informant on the event loop +#[deprecated(note = "Please use informant::build instead, and then create the task manually")] pub fn start(service: &Service, exit: ::exit_future::Exit, handle: TaskExecutor) where C: Components, { + handle.spawn(exit.until(build(service)).map(|_| ())); +} + +/// Creates an informant in the form of a `Future` that must be polled regularly. +pub fn build(service: &Service) -> impl Future +where C: Components { let network = service.network(); let client = service.client(); let txpool = service.transaction_pool(); @@ -156,8 +163,8 @@ pub fn start(service: &Service, exit: ::exit_future::Exit, handle: TaskExe Ok(()) }); - let informant_work = display_notifications.join3(display_block_import, display_txpool_import); - handle.spawn(exit.until(informant_work).map(|_| ())); + display_notifications.join3(display_block_import, display_txpool_import) + .map(|((), (), ())| ()) } fn speed(best_number: u64, last_number: Option, last_update: time::Instant) -> String { diff --git a/substrate/node-template/src/cli.rs b/substrate/node-template/src/cli.rs index f41674631e..cd148f3462 100644 --- a/substrate/node-template/src/cli.rs +++ b/substrate/node-template/src/cli.rs @@ -61,8 +61,8 @@ fn run_until_exit( { let (exit_send, exit) = exit_future::signal(); - let executor = runtime.executor(); - informant::start(&service, exit.clone(), executor.clone()); + let informant = informant::build(&service); + runtime.executor().spawn(exit.until(informant).map(|_| ())); let _ = runtime.block_on(e.into_exit()); exit_send.fire(); diff --git a/substrate/node/cli/src/lib.rs b/substrate/node/cli/src/lib.rs index cbb0628a91..886c6eef77 100644 --- a/substrate/node/cli/src/lib.rs +++ b/substrate/node/cli/src/lib.rs @@ -118,8 +118,8 @@ fn run_until_exit( { let (exit_send, exit) = exit_future::signal(); - let executor = runtime.executor(); - cli::informant::start(&service, exit.clone(), executor.clone()); + let informant = cli::informant::build(&service); + runtime.executor().spawn(exit.until(informant).map(|_| ())); let _ = runtime.block_on(e.into_exit()); exit_send.fire();