Upgrade from futures-preview to futures 0.3.1, and remove futures 0.1 where currently possible (#4083)

* Migrate node and node-template

* Migrate srml

* Simple changes

* Add async-std for interval

* Fix test-runtime warning

* Small changes

* move futures01 in core/rpc to dev-deps

* Change wasm CI builds

* Switch to async-std 1.0.1

* Remove async-std dep of network

* Add modified lockfile

* Fix node cli browser build

* Remove authority-discovery async-std dep

* Add Send + Sync to interval dyn stream
This commit is contained in:
Ashley
2019-11-22 13:06:23 +01:00
committed by Gavin Wood
parent 795701608c
commit 1735683cc9
57 changed files with 240 additions and 224 deletions
+11 -9
View File
@@ -17,8 +17,7 @@
//! Console informant. Prints sync progress and block events. Runs on the calling thread.
use client_api::BlockchainEvents;
use futures::{Future, Stream};
use futures03::{StreamExt as _, TryStreamExt as _};
use futures::{StreamExt, TryStreamExt, FutureExt, future, compat::Stream01CompatExt};
use log::{info, warn};
use sr_primitives::traits::Header;
use service::AbstractService;
@@ -27,17 +26,18 @@ use std::time::Duration;
mod display;
/// Creates an informant in the form of a `Future` that must be polled regularly.
pub fn build(service: &impl AbstractService) -> impl Future<Item = (), Error = ()> {
pub fn build(service: &impl AbstractService) -> impl futures::Future<Output = ()> {
let client = service.client();
let mut display = display::InformantDisplay::new();
let display_notifications = service
.network_status(Duration::from_millis(5000))
.for_each(move |(net_status, _)| {
.compat()
.try_for_each(move |(net_status, _)| {
let info = client.info();
display.display(&info, net_status);
Ok(())
future::ok(())
});
let client = service.client();
@@ -46,7 +46,7 @@ pub fn build(service: &impl AbstractService) -> impl Future<Item = (), Error = (
Some((info.chain.best_number, info.chain.best_hash))
};
let display_block_import = client.import_notification_stream().map(|v| Ok::<_, ()>(v)).compat().for_each(move |n| {
let display_block_import = client.import_notification_stream().for_each(move |n| {
// detect and log reorganizations.
if let Some((ref last_num, ref last_hash)) = last_best {
if n.header.parent_hash() != last_hash && n.is_new_best {
@@ -74,9 +74,11 @@ pub fn build(service: &impl AbstractService) -> impl Future<Item = (), Error = (
}
info!(target: "substrate", "Imported #{} ({})", n.header.number(), n.hash);
Ok(())
future::ready(())
});
display_notifications.join(display_block_import)
.map(|((), ())| ())
future::join(
display_notifications,
display_block_import
).map(|_| ())
}
+11 -7
View File
@@ -61,8 +61,8 @@ pub use traits::{GetLogFilter, AugmentClap};
use app_dirs::{AppInfo, AppDataType};
use log::info;
use lazy_static::lazy_static;
use futures::{Async, Future};
use futures::{Future, FutureExt, TryFutureExt};
use futures01::{Async, Future as _};
use substrate_telemetry::TelemetryEndpoints;
/// default sub directory to store network config
@@ -102,7 +102,7 @@ pub struct VersionInfo {
/// Something that can be converted into an exit signal.
pub trait IntoExit {
/// Exit signal type.
type Exit: Future<Item=(),Error=()> + Send + 'static;
type Exit: Future<Output=()> + Unpin + Send + 'static;
/// Convert into exit signal.
fn into_exit(self) -> Self::Exit;
}
@@ -391,14 +391,16 @@ impl<'a> ParseAndPrepareExport<'a> {
// 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();
let exit = exit.into_exit()
.map(|_| Ok::<_, ()>(()))
.compat();
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(|| {
let fut = futures01::future::poll_fn(|| {
if exit_recv.try_recv().is_ok() {
return Ok(Async::Ready(()));
}
@@ -453,14 +455,16 @@ impl<'a> ParseAndPrepareImport<'a> {
// 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();
let exit = exit.into_exit()
.map(|_| Ok::<_, ()>(()))
.compat();
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(|| {
let fut = futures01::future::poll_fn(|| {
if exit_recv.try_recv().is_ok() {
return Ok(Async::Ready(()));
}