From a116eff2622f2eb3ab2a62a7cbca10af5634a6bb Mon Sep 17 00:00:00 2001
From: librelois <elois@ifee.fr>
Date: Sun, 3 Nov 2019 23:01:51 +0100
Subject: [PATCH] [ref] bc: import mpsc Sender and Receiver directly

---
 lib/modules/blockchain/blockchain/src/lib.rs       | 14 +++++++-------
 .../blockchain/src/sync/apply/blocks_worker.rs     |  5 ++---
 .../blockchain/src/sync/apply/txs_worker.rs        |  5 ++---
 .../blockchain/src/sync/apply/wot_worker.rs        |  5 ++---
 .../src/sync/download/json_reader_worker.rs        |  3 +--
 5 files changed, 14 insertions(+), 18 deletions(-)

diff --git a/lib/modules/blockchain/blockchain/src/lib.rs b/lib/modules/blockchain/blockchain/src/lib.rs
index 4674ca8f..812f15d0 100644
--- a/lib/modules/blockchain/blockchain/src/lib.rs
+++ b/lib/modules/blockchain/blockchain/src/lib.rs
@@ -45,7 +45,7 @@ mod sync;
 use std::collections::{HashMap, HashSet};
 use std::path::PathBuf;
 use std::str;
-use std::sync::mpsc;
+use std::sync::mpsc::{Receiver, RecvTimeoutError, Sender};
 use std::time::{Duration, SystemTime, UNIX_EPOCH};
 
 use crate::constants::*;
@@ -88,7 +88,7 @@ pub static DISTANCE_CALCULATOR: &RustyDistanceCalculator = &RustyDistanceCalcula
 /// Blockchain Module
 pub struct BlockchainModule {
     /// Router sender
-    pub router_sender: mpsc::Sender<RouterThreadMessage<DursMsg>>,
+    pub router_sender: Sender<RouterThreadMessage<DursMsg>>,
     ///Path to the user datas profile
     pub profile_path: PathBuf,
     /// Currency
@@ -177,7 +177,7 @@ impl BlockchainModule {
     /// Loading blockchain configuration
     pub fn load_blockchain_conf(
         db: Db,
-        router_sender: mpsc::Sender<RouterThreadMessage<DursMsg>>,
+        router_sender: Sender<RouterThreadMessage<DursMsg>>,
         profile_path: PathBuf,
         _keys: RequiredKeysContent,
     ) -> BlockchainModule {
@@ -251,7 +251,7 @@ impl BlockchainModule {
     /// Start blockchain module.
     pub fn start_blockchain(
         &mut self,
-        blockchain_receiver: &mpsc::Receiver<DursMsg>,
+        blockchain_receiver: &Receiver<DursMsg>,
         sync_opts: Option<SyncOpt>,
     ) {
         info!("BlockchainModule::start_blockchain()");
@@ -286,7 +286,7 @@ impl BlockchainModule {
     }
 
     /// Start blockchain main loop
-    pub fn main_loop(&mut self, blockchain_receiver: &mpsc::Receiver<DursMsg>) {
+    pub fn main_loop(&mut self, blockchain_receiver: &Receiver<DursMsg>) {
         // Init main loop datas
         let mut last_get_stackables_blocks = UNIX_EPOCH;
 
@@ -326,10 +326,10 @@ impl BlockchainModule {
                     }
                 }
                 Err(e) => match e {
-                    mpsc::RecvTimeoutError::Disconnected => {
+                    RecvTimeoutError::Disconnected => {
                         fatal_error!("Disconnected blockchain module !");
                     }
-                    mpsc::RecvTimeoutError::Timeout => {}
+                    RecvTimeoutError::Timeout => {}
                 },
             }
             // Try to apply local stackable blocks every 20 seconds
diff --git a/lib/modules/blockchain/blockchain/src/sync/apply/blocks_worker.rs b/lib/modules/blockchain/blockchain/src/sync/apply/blocks_worker.rs
index 556fa5b5..f88328b3 100644
--- a/lib/modules/blockchain/blockchain/src/sync/apply/blocks_worker.rs
+++ b/lib/modules/blockchain/blockchain/src/sync/apply/blocks_worker.rs
@@ -15,12 +15,11 @@
 
 use crate::sync::*;
 use pbr::ProgressBar;
-use std::sync::mpsc;
 
 pub fn execute(
     pool: &ThreadPool,
-    sender_sync_thread: mpsc::Sender<MessForSyncThread>,
-    recv: mpsc::Receiver<SyncJobsMess>,
+    sender_sync_thread: Sender<MessForSyncThread>,
+    recv: Receiver<SyncJobsMess>,
     db: Db,
     target_blockstamp: Blockstamp,
     mut apply_pb: ProgressBar<std::io::Stdout>,
diff --git a/lib/modules/blockchain/blockchain/src/sync/apply/txs_worker.rs b/lib/modules/blockchain/blockchain/src/sync/apply/txs_worker.rs
index 5b8b0d2f..6a1a0f43 100644
--- a/lib/modules/blockchain/blockchain/src/sync/apply/txs_worker.rs
+++ b/lib/modules/blockchain/blockchain/src/sync/apply/txs_worker.rs
@@ -14,13 +14,12 @@
 // along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 use crate::sync::*;
-use std::sync::mpsc;
 
 pub fn execute(
     pool: &ThreadPool,
     profile_path: PathBuf,
-    sender_sync_thread: mpsc::Sender<MessForSyncThread>,
-    recv: mpsc::Receiver<SyncJobsMess>,
+    sender_sync_thread: Sender<MessForSyncThread>,
+    recv: Receiver<SyncJobsMess>,
 ) {
     // Launch tx_worker thread
     pool.execute(move || {
diff --git a/lib/modules/blockchain/blockchain/src/sync/apply/wot_worker.rs b/lib/modules/blockchain/blockchain/src/sync/apply/wot_worker.rs
index 4c245a71..2109f199 100644
--- a/lib/modules/blockchain/blockchain/src/sync/apply/wot_worker.rs
+++ b/lib/modules/blockchain/blockchain/src/sync/apply/wot_worker.rs
@@ -15,13 +15,12 @@
 
 use crate::sync::*;
 use std::ops::Deref;
-use std::sync::mpsc;
 
 pub fn execute(
     pool: &ThreadPool,
     profile_path: PathBuf,
-    sender_sync_thread: mpsc::Sender<MessForSyncThread>,
-    recv: mpsc::Receiver<SyncJobsMess>,
+    sender_sync_thread: Sender<MessForSyncThread>,
+    recv: Receiver<SyncJobsMess>,
 ) {
     // Launch wot_worker thread
     pool.execute(move || {
diff --git a/lib/modules/blockchain/blockchain/src/sync/download/json_reader_worker.rs b/lib/modules/blockchain/blockchain/src/sync/download/json_reader_worker.rs
index 8dcbfb64..029afb83 100644
--- a/lib/modules/blockchain/blockchain/src/sync/download/json_reader_worker.rs
+++ b/lib/modules/blockchain/blockchain/src/sync/download/json_reader_worker.rs
@@ -23,7 +23,6 @@ use rayon::prelude::*;
 use std::collections::HashSet;
 use std::io::Read;
 use std::path::{Path, PathBuf};
-use std::sync::mpsc;
 use threadpool::ThreadPool;
 
 /// Number of chunk parsed before sending them to the apply workers
@@ -33,7 +32,7 @@ static CHUNKS_STEP: &usize = &16;
 pub fn json_reader_worker(
     pool: &ThreadPool,
     profile_path: PathBuf,
-    sender_sync_thread: mpsc::Sender<MessForSyncThread>,
+    sender_sync_thread: Sender<MessForSyncThread>,
     json_chunks_path: PathBuf,
     end: Option<u32>,
 ) {
-- 
GitLab