diff --git a/beacon_node/websocket_server/Cargo.toml b/beacon_node/websocket_server/Cargo.toml index 0ed8d628cc..e53e0a917f 100644 --- a/beacon_node/websocket_server/Cargo.toml +++ b/beacon_node/websocket_server/Cargo.toml @@ -7,11 +7,11 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -futures = "0.1.29" +futures = "0.3" serde = "1.0.102" serde_derive = "1.0.102" serde_json = "1.0.41" slog = "2.5.2" -tokio = "0.1.22" +tokio = { version = "0.2", features = ["full"] } types = { path = "../../eth2/types" } ws = "0.9.1" diff --git a/beacon_node/websocket_server/src/lib.rs b/beacon_node/websocket_server/src/lib.rs index 01b48ab18b..c6f1b537cc 100644 --- a/beacon_node/websocket_server/src/lib.rs +++ b/beacon_node/websocket_server/src/lib.rs @@ -1,9 +1,8 @@ -use futures::Future; +use futures::future::TryFutureExt; use slog::{debug, error, info, warn, Logger}; use std::marker::PhantomData; use std::net::SocketAddr; -use std::thread; -use tokio::runtime::TaskExecutor; +use tokio::runtime::Handle; use types::EthSpec; use ws::{Sender, WebSocket}; @@ -38,7 +37,7 @@ impl WebSocketSender { pub fn start_server( config: &Config, - executor: &TaskExecutor, + handle: &Handle, log: &Logger, ) -> Result< ( @@ -87,19 +86,21 @@ pub fn start_server( } else { info!(log_inner, "Websocket server shutdown"); } - Ok(()) + futures::future::ok(()) }) .map_err(|_| ()); - // Place a future on the executor that will shutdown the websocket server when the + // Place a future on the handle that will shutdown the websocket server when the // application exits. - executor.spawn(exit_future); + handle.spawn(exit_future); exit_channel }; let log_inner = log.clone(); - let _handle = thread::spawn(move || match server.run() { + // TODO: using tokio `spawn_blocking` instead of `thread::spawn` + // Check which is more apt + let _handle = tokio::task::spawn_blocking(move || match server.run() { Ok(_) => { debug!( log_inner,