From 6431cdf601627863d0e93e5bb2482eea019b507c Mon Sep 17 00:00:00 2001 From: Pierre Krieger <pierre.krieger1708@gmail.com> Date: Thu, 23 May 2019 10:44:36 +0200 Subject: [PATCH] Remove TaskExecutor from the API of the informant (#2642) * Remove TaskExecutor from the API of the informant * Fix node-template --- substrate/core/cli/src/informant.rs | 11 +++++++++-- substrate/node-template/src/cli.rs | 4 ++-- substrate/node/cli/src/lib.rs | 4 ++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/substrate/core/cli/src/informant.rs b/substrate/core/cli/src/informant.rs index dd0237b7f84..5c60229fab1 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<C>(service: &Service<C>, 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<C>(service: &Service<C>) -> impl Future<Item = (), Error = ()> +where C: Components { let network = service.network(); let client = service.client(); let txpool = service.transaction_pool(); @@ -156,8 +163,8 @@ pub fn start<C>(service: &Service<C>, 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<u64>, last_update: time::Instant) -> String { diff --git a/substrate/node-template/src/cli.rs b/substrate/node-template/src/cli.rs index f41674631e8..cd148f3462d 100644 --- a/substrate/node-template/src/cli.rs +++ b/substrate/node-template/src/cli.rs @@ -61,8 +61,8 @@ fn run_until_exit<T, C, E>( { 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 cbb0628a912..886c6eef772 100644 --- a/substrate/node/cli/src/lib.rs +++ b/substrate/node/cli/src/lib.rs @@ -118,8 +118,8 @@ fn run_until_exit<T, C, E>( { 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(); -- GitLab