mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 15:37:56 +00:00
Remove the exit parameter from importing and exporting blocks (#3954)
* export_blocks now generates a Future * Handle the export blocks exit in substrate-cli instead * Turn import_blocks entirely into a Future * Move the exit parameter to substrate-cli for imports
This commit is contained in:
committed by
Bastian Köcher
parent
75a0a3f6fd
commit
f9a4cff50a
@@ -62,7 +62,7 @@ use app_dirs::{AppInfo, AppDataType};
|
||||
use log::info;
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use futures::Future;
|
||||
use futures::{Async, Future};
|
||||
use substrate_telemetry::TelemetryEndpoints;
|
||||
|
||||
/// default sub directory to store network config
|
||||
@@ -388,7 +388,25 @@ impl<'a> ParseAndPrepareExport<'a> {
|
||||
None => Box::new(stdout()),
|
||||
};
|
||||
|
||||
builder(config)?.export_blocks(exit.into_exit(), file, from.into(), to.map(Into::into), json)?;
|
||||
// Note: while we would like the user to handle the exit themselves, we handle it here
|
||||
// for backwards compatibility reasons.
|
||||
let (exit_send, exit_recv) = std::sync::mpsc::channel();
|
||||
let exit = exit.into_exit();
|
||||
std::thread::spawn(move || {
|
||||
let _ = exit.wait();
|
||||
let _ = exit_send.send(());
|
||||
});
|
||||
|
||||
let mut export_fut = builder(config)?.export_blocks(file, from.into(), to.map(Into::into), json);
|
||||
let fut = futures::future::poll_fn(|| {
|
||||
if exit_recv.try_recv().is_ok() {
|
||||
return Ok(Async::Ready(()));
|
||||
}
|
||||
export_fut.poll()
|
||||
});
|
||||
|
||||
let mut runtime = tokio::runtime::current_thread::Runtime::new().unwrap();
|
||||
runtime.block_on(fut)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -423,7 +441,7 @@ impl<'a> ParseAndPrepareImport<'a> {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let file: Box<dyn ReadPlusSeek> = match self.params.input {
|
||||
let file: Box<dyn ReadPlusSeek + Send> = match self.params.input {
|
||||
Some(filename) => Box::new(File::open(filename)?),
|
||||
None => {
|
||||
let mut buffer = Vec::new();
|
||||
@@ -432,8 +450,25 @@ impl<'a> ParseAndPrepareImport<'a> {
|
||||
},
|
||||
};
|
||||
|
||||
let fut = builder(config)?.import_blocks(exit.into_exit(), file)?;
|
||||
tokio::run(fut);
|
||||
// Note: while we would like the user to handle the exit themselves, we handle it here
|
||||
// for backwards compatibility reasons.
|
||||
let (exit_send, exit_recv) = std::sync::mpsc::channel();
|
||||
let exit = exit.into_exit();
|
||||
std::thread::spawn(move || {
|
||||
let _ = exit.wait();
|
||||
let _ = exit_send.send(());
|
||||
});
|
||||
|
||||
let mut import_fut = builder(config)?.import_blocks(file);
|
||||
let fut = futures::future::poll_fn(|| {
|
||||
if exit_recv.try_recv().is_ok() {
|
||||
return Ok(Async::Ready(()));
|
||||
}
|
||||
import_fut.poll()
|
||||
});
|
||||
|
||||
let mut runtime = tokio::runtime::current_thread::Runtime::new().unwrap();
|
||||
runtime.block_on(fut)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user