Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Upgrade tokio
Browse files Browse the repository at this point in the history
  • Loading branch information
expenses committed Jan 10, 2020
1 parent cd25fcc commit 078992f
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 45 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions bin/node-template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ path = "src/main.rs"

[dependencies]
futures = "0.3.1"
futures01 = { package = "futures", version = "0.1.29" }
ctrlc = { version = "3.1.3", features = ["termination"] }
log = "0.4.8"
tokio = "0.1.22"
tokio = { version = "0.2", features = ["rt-threaded"] }
parking_lot = "0.9.0"
codec = { package = "parity-scale-codec", version = "1.0.0" }
trie-root = "0.15.2"
Expand Down
28 changes: 9 additions & 19 deletions bin/node-template/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::service;
use futures::{future::{select, Map}, FutureExt, TryFutureExt, channel::oneshot};
use futures::{future::{select, Map, Either}, FutureExt, channel::oneshot};
use std::cell::RefCell;
use tokio::runtime::Runtime;
pub use sc_cli::{VersionInfo, IntoExit, error};
Expand Down Expand Up @@ -75,33 +75,23 @@ where

let informant = informant::build(&service);

let future = select(exit, informant)
.map(|_| Ok(()))
.compat();

runtime.executor().spawn(future);
let handle = runtime.spawn(select(exit, informant));

// we eagerly drop the service so that the internal exit future is fired,
// but we need to keep holding a reference to the global telemetry guard
let _telemetry = service.telemetry();

let service_res = {
let exit = e.into_exit();
let select = select(service, exit)
.map(|_| Ok(()))
.compat();
runtime.block_on(select)
};
let exit = e.into_exit();
let service_res = runtime.block_on(select(service, exit));

let _ = exit_send.send(());

// TODO [andre]: timeout this future #1318

use futures01::Future;
runtime.block_on(handle);

let _ = runtime.shutdown_on_idle().wait();

service_res
match service_res {
Either::Left((res, _)) => res.map_err(error::Error::Service),
Either::Right((_, _)) => Ok(())
}
}

// handles ctrl-c
Expand Down
2 changes: 1 addition & 1 deletion bin/node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ node-primitives = { version = "2.0.0", path = "../primitives" }
node-executor = { version = "2.0.0", path = "../executor" }

# CLI-specific dependencies
tokio = { version = "0.1.22", optional = true }
tokio = { version = "0.2", features = ["rt-threaded"], optional = true }
sc-cli = { version = "2.0.0", optional = true, path = "../../../client/cli" }
ctrlc = { version = "3.1.3", features = ["termination"], optional = true }
node-transaction-factory = { version = "2.0.0", optional = true, path = "../transaction-factory" }
Expand Down
32 changes: 13 additions & 19 deletions bin/node/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

pub use sc_cli::VersionInfo;
use tokio::prelude::Future;
use tokio::runtime::{Builder as RuntimeBuilder, Runtime};
use sc_cli::{IntoExit, NoCustom, SharedParams, ImportParams, error};
use sc_service::{AbstractService, Roles as ServiceRoles, Configuration};
Expand All @@ -25,6 +24,7 @@ use sc_cli::{display_role, parse_and_prepare, GetSharedParams, ParseAndPrepare};
use crate::{service, ChainSpec, load_spec};
use crate::factory_impl::FactoryState;
use node_transaction_factory::RuntimeAdapter;
use futures::{channel::oneshot, future::{select, Either}};

/// Custom subcommands.
#[derive(Clone, Debug, StructOpt)]
Expand Down Expand Up @@ -105,7 +105,10 @@ pub fn run<I, T, E>(args: I, exit: E, version: sc_cli::VersionInfo) -> error::Re
info!("Chain specification: {}", config.chain_spec.name());
info!("Node name: {}", config.name);
info!("Roles: {}", display_role(&config));
let runtime = RuntimeBuilder::new().name_prefix("main-tokio-").build()
let runtime = RuntimeBuilder::new()
.thread_name("main-tokio-")
.threaded_scheduler()
.build()
.map_err(|e| format!("{:?}", e))?;
match config.roles {
ServiceRoles::LIGHT => run_until_exit(
Expand Down Expand Up @@ -172,34 +175,25 @@ where
T: AbstractService,
E: IntoExit,
{
use futures::{FutureExt, TryFutureExt, channel::oneshot, future::select};

let (exit_send, exit) = oneshot::channel();

let informant = sc_cli::informant::build(&service);

let future = select(informant, exit)
.map(|_| Ok(()))
.compat();

runtime.executor().spawn(future);
let handle = runtime.spawn(select(exit, informant));

// we eagerly drop the service so that the internal exit future is fired,
// but we need to keep holding a reference to the global telemetry guard
let _telemetry = service.telemetry();

let service_res = {
let exit = e.into_exit();
let select = select(service, exit)
.map(|_| Ok(()))
.compat();
runtime.block_on(select)
};
let exit = e.into_exit();
let service_res = runtime.block_on(select(service, exit));

let _ = exit_send.send(());

// TODO [andre]: timeout this future #1318
let _ = runtime.shutdown_on_idle().wait();
runtime.block_on(handle);

service_res
match service_res {
Either::Left((res, _)) => res.map_err(error::Error::Service),
Either::Right((_, _)) => Ok(())
}
}
2 changes: 1 addition & 1 deletion client/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ time = "0.1.42"
ansi_term = "0.12.1"
lazy_static = "1.4.0"
app_dirs = "1.2.1"
tokio = "0.2.1"
tokio = "0.2"
futures = "0.3.1"
fdlimit = "0.1.1"
serde_json = "1.0.41"
Expand Down

0 comments on commit 078992f

Please sign in to comment.