Skip to content

Commit

Permalink
Update async-std runtime setup (#526)
Browse files Browse the repository at this point in the history
* Update async-std runtime setup

* Update ctrl-c handler setup
  • Loading branch information
austinabell authored Jun 30, 2020
1 parent a2cab73 commit e0d574e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 35 deletions.
24 changes: 12 additions & 12 deletions blockchain/beacon/src/drand_api/api.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is generated by rust-protobuf 2.15.0. Do not edit
// This file is generated by rust-protobuf 2.15.1. Do not edit
// @generated

// https://github.com/rust-lang/rust-clippy/issues/702
Expand All @@ -25,7 +25,7 @@ use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions;

/// Generated files are compatible only with the same version
/// of protobuf runtime.
// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_15_0;
// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_15_1;

#[derive(PartialEq,Clone,Default)]
pub struct PublicRandRequest {
Expand Down Expand Up @@ -125,7 +125,7 @@ impl ::protobuf::Message for PublicRandRequest {
fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) {
self as &mut dyn (::std::any::Any)
}
fn into_any(self: Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
fn into_any(self: ::std::boxed::Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
self
}

Expand Down Expand Up @@ -389,7 +389,7 @@ impl ::protobuf::Message for PublicRandResponse {
fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) {
self as &mut dyn (::std::any::Any)
}
fn into_any(self: Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
fn into_any(self: ::std::boxed::Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
self
}

Expand Down Expand Up @@ -585,7 +585,7 @@ impl ::protobuf::Message for PrivateRandRequest {
fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) {
self as &mut dyn (::std::any::Any)
}
fn into_any(self: Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
fn into_any(self: ::std::boxed::Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
self
}

Expand Down Expand Up @@ -763,7 +763,7 @@ impl ::protobuf::Message for PrivateRandResponse {
fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) {
self as &mut dyn (::std::any::Any)
}
fn into_any(self: Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
fn into_any(self: ::std::boxed::Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
self
}

Expand Down Expand Up @@ -998,7 +998,7 @@ impl ::protobuf::Message for ECIES {
fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) {
self as &mut dyn (::std::any::Any)
}
fn into_any(self: Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
fn into_any(self: ::std::boxed::Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
self
}

Expand Down Expand Up @@ -1136,7 +1136,7 @@ impl ::protobuf::Message for DistKeyRequest {
fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) {
self as &mut dyn (::std::any::Any)
}
fn into_any(self: Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
fn into_any(self: ::std::boxed::Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
self
}

Expand Down Expand Up @@ -1293,7 +1293,7 @@ impl ::protobuf::Message for DistKeyResponse {
fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) {
self as &mut dyn (::std::any::Any)
}
fn into_any(self: Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
fn into_any(self: ::std::boxed::Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
self
}

Expand Down Expand Up @@ -1419,7 +1419,7 @@ impl ::protobuf::Message for HomeRequest {
fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) {
self as &mut dyn (::std::any::Any)
}
fn into_any(self: Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
fn into_any(self: ::std::boxed::Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
self
}

Expand Down Expand Up @@ -1576,7 +1576,7 @@ impl ::protobuf::Message for HomeResponse {
fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) {
self as &mut dyn (::std::any::Any)
}
fn into_any(self: Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
fn into_any(self: ::std::boxed::Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
self
}

Expand Down Expand Up @@ -1804,7 +1804,7 @@ impl ::protobuf::Message for Node {
fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) {
self as &mut dyn (::std::any::Any)
}
fn into_any(self: Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
fn into_any(self: ::std::boxed::Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
self
}

Expand Down
12 changes: 6 additions & 6 deletions blockchain/beacon/src/drand_api/common.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file is generated by rust-protobuf 2.15.0. Do not edit
// This file is generated by rust-protobuf 2.15.1. Do not edit
// @generated

// https://github.com/rust-lang/rust-clippy/issues/702
Expand All @@ -25,7 +25,7 @@ use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions;

/// Generated files are compatible only with the same version
/// of protobuf runtime.
// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_15_0;
// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_15_1;

#[derive(PartialEq,Clone,Default)]
pub struct Empty {
Expand Down Expand Up @@ -95,7 +95,7 @@ impl ::protobuf::Message for Empty {
fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) {
self as &mut dyn (::std::any::Any)
}
fn into_any(self: Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
fn into_any(self: ::std::boxed::Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
self
}

Expand Down Expand Up @@ -317,7 +317,7 @@ impl ::protobuf::Message for Identity {
fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) {
self as &mut dyn (::std::any::Any)
}
fn into_any(self: Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
fn into_any(self: ::std::boxed::Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
self
}

Expand Down Expand Up @@ -686,7 +686,7 @@ impl ::protobuf::Message for GroupPacket {
fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) {
self as &mut dyn (::std::any::Any)
}
fn into_any(self: Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
fn into_any(self: ::std::boxed::Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
self
}

Expand Down Expand Up @@ -848,7 +848,7 @@ impl ::protobuf::Message for GroupRequest {
fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) {
self as &mut dyn (::std::any::Any)
}
fn into_any(self: Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
fn into_any(self: ::std::boxed::Box<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
self
}

Expand Down
5 changes: 2 additions & 3 deletions forest/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ mod genesis;
pub use self::config::Config;
pub(super) use self::genesis::initialize_genesis;

use async_std::task;
use std::cell::RefCell;
use std::io;
use std::process;
Expand Down Expand Up @@ -80,7 +79,7 @@ impl DaemonOpts {
}

/// Blocks current thread until ctrl-c is received
pub(super) fn block_until_sigint() {
pub(super) async fn block_until_sigint() {
let (ctrlc_send, ctrlc_oneshot) = futures::channel::oneshot::channel();
let ctrlc_send_c = RefCell::new(Some(ctrlc_send));

Expand All @@ -99,5 +98,5 @@ pub(super) fn block_until_sigint() {
})
.expect("Error setting Ctrl-C handler");

task::block_on(ctrlc_oneshot).unwrap();
ctrlc_oneshot.await.unwrap();
}
12 changes: 6 additions & 6 deletions forest/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::sync::Arc;
use utils::write_to_file;

/// Starts daemon process
pub(super) fn start(config: Config) {
pub(super) async fn start(config: Config) {
info!("Starting Forest daemon");
let net_keypair = get_keypair(&format!("{}{}", &config.data_dir, "/libp2p/keypair"))
.unwrap_or_else(|| {
Expand Down Expand Up @@ -80,12 +80,12 @@ pub(super) fn start(config: Config) {
});

// Block until ctrl-c is hit
block_until_sigint();
block_until_sigint().await;

// Drop threads
drop(rpc_thread);
drop(p2p_thread);
drop(sync_thread);
// Cancel all async services
rpc_thread.cancel().await;
p2p_thread.cancel().await;
sync_thread.cancel().await;

info!("Forest finish shutdown");
}
7 changes: 4 additions & 3 deletions forest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ mod subcommand;
use cli::CLI;
use structopt::StructOpt;

fn main() {
#[async_std::main]
async fn main() {
logger::setup_logger();

// Capture CLI inputs
match CLI::from_args() {
CLI {
daemon_opts,
cmd: None,
} => daemon::start(daemon_opts.to_config().unwrap()),
} => daemon::start(daemon_opts.to_config().unwrap()).await,
CLI {
cmd: Some(command), ..
} => subcommand::process(command),
} => subcommand::process(command).await,
}
}
7 changes: 2 additions & 5 deletions forest/src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use super::cli::Subcommand;
use super::paramfetch::{get_params_default, SectorSizeOpt};
use async_std::task;
use fil_types::SectorSize;

/// Converts a human readable string to a u64 size.
Expand All @@ -27,7 +26,7 @@ fn ram_to_int(size: &str) -> Result<SectorSize, String> {
}

/// Process CLI subcommand
pub(super) fn process(command: Subcommand) {
pub(super) async fn process(command: Subcommand) {
match command {
Subcommand::FetchParams {
params_size,
Expand All @@ -48,9 +47,7 @@ pub(super) fn process(command: Subcommand) {
);
};

task::block_on(async {
get_params_default(sizes, verbose).await.unwrap();
});
get_params_default(sizes, verbose).await.unwrap();
}
}
}
Expand Down

0 comments on commit e0d574e

Please sign in to comment.