,
}
+impl IntoExit for CollationNode
where
+ P: ParachainContext + Send + 'static,
+ E: Future- + Send + 'static
+{
+ type Exit = E;
+ fn into_exit(self) -> Self::Exit {
+ self.exit
+ }
+}
+
impl
Worker for CollationNode
where
P: ParachainContext + Send + 'static,
- E: Future- + Send + Clone + 'static
+ E: Future
- + Send + 'static
{
type Work = Box
+ Send>;
- type Exit = E;
fn configuration(&self) -> CustomConfiguration {
let mut config = CustomConfiguration::default();
@@ -227,10 +236,6 @@ impl Worker for CollationNode
where
config
}
- fn exit_only(&self) -> Self::Exit {
- self.exit.clone()
- }
-
fn work(self, service: &Service) -> Self::Work {
let CollationNode { parachain_context, exit, para_id, key } = self;
let client = service.client();
diff --git a/polkadot/src/main.rs b/polkadot/src/main.rs
index 4e3fba054f962..d3e951596e200 100644
--- a/polkadot/src/main.rs
+++ b/polkadot/src/main.rs
@@ -38,11 +38,9 @@ mod vergen {
// the regular polkadot worker simply does nothing until ctrl-c
struct Worker;
-impl cli::Worker for Worker {
- type Work = Self::Exit;
+impl cli::IntoExit for Worker {
type Exit = future::MapErr, fn(oneshot::Canceled) -> ()>;
-
- fn exit_only(&self) -> Self::Exit {
+ fn into_exit(self) -> Self::Exit {
// can't use signal directly here because CtrlC takes only `Fn`.
let (exit_send, exit) = oneshot::channel();
@@ -55,9 +53,13 @@ impl cli::Worker for Worker {
exit.map_err(drop)
}
+}
- fn work(self, _service: &Service) -> Self::Exit {
- self.exit_only()
+impl cli::Worker for Worker {
+ type Work = ::Exit;
+ fn work(self, _service: &Service) -> Self::Work {
+ use cli::IntoExit;
+ self.into_exit()
}
}
diff --git a/substrate/cli/src/lib.rs b/substrate/cli/src/lib.rs
index 4feeb711f3738..324121073eae6 100644
--- a/substrate/cli/src/lib.rs
+++ b/substrate/cli/src/lib.rs
@@ -85,11 +85,19 @@ pub struct VersionInfo {
}
/// CLI Action
-pub enum Action {
+pub enum Action {
/// Substrate handled the command. No need to do anything.
ExecutedInternally,
/// Service mode requested. Caller should start the service.
- RunService(FactoryFullConfiguration),
+ RunService((FactoryFullConfiguration, E)),
+}
+
+/// Something that can be converted into an exit signal.
+pub trait IntoExit {
+ /// Exit signal type.
+ type Exit: Future- + Send + 'static;
+ /// Convert into exit signal.
+ fn into_exit(self) -> Self::Exit;
}
fn load_spec
(matches: &clap::ArgMatches, factory: F) -> Result, String>
@@ -146,11 +154,11 @@ pub fn prepare_execution(
version: VersionInfo,
spec_factory: S,
impl_name: &'static str,
-) -> error::Result>
+) -> error::Result>
where
I: IntoIterator- ,
T: Into
+ Clone,
- E: Future- + Send + 'static,
+ E: IntoExit,
F: ServiceFactory,
S: FnOnce(&str) -> Result
>>, String>,
{
@@ -182,13 +190,13 @@ where
if let Some(matches) = matches.subcommand_matches("export-blocks") {
let spec = load_spec(&matches, spec_factory)?;
- export_blocks::(matches, spec, exit)?;
+ export_blocks::(matches, spec, exit.into_exit())?;
return Ok(Action::ExecutedInternally);
}
if let Some(matches) = matches.subcommand_matches("import-blocks") {
let spec = load_spec(&matches, spec_factory)?;
- import_blocks::(matches, spec, exit)?;
+ import_blocks::(matches, spec, exit.into_exit())?;
return Ok(Action::ExecutedInternally);
}
@@ -298,7 +306,7 @@ where
config.telemetry_url = Some(url.to_owned());
}
- Ok(Action::RunService(config))
+ Ok(Action::RunService((config, exit)))
}
fn build_spec(matches: &clap::ArgMatches, spec: ChainSpec>) -> error::Result<()>