Tidy "sync" module

This commit is contained in:
Paul Hauner 2018-08-23 15:11:59 +10:00
parent 366dca710f
commit abefec8ed8

View File

@ -6,8 +6,6 @@ use self::futures::sync::mpsc::{
UnboundedReceiver, UnboundedReceiver,
UnboundedSender, UnboundedSender,
}; };
use self::futures::Stream;
use self::tokio::timer::Interval;
use self::tokio::prelude::*; use self::tokio::prelude::*;
use std::sync::{ RwLock, Arc }; use std::sync::{ RwLock, Arc };
use super::network_libp2p::message::{ use super::network_libp2p::message::{
@ -17,17 +15,21 @@ use super::network_libp2p::message::{
use super::db::DB; use super::db::DB;
use slog::Logger; use slog::Logger;
use std::time::{ Duration, Instant };
type NetworkSender = UnboundedSender<OutgoingMessage>; type NetworkSender = UnboundedSender<OutgoingMessage>;
type NetworkReceiver = UnboundedReceiver<NetworkEvent>; type NetworkReceiver = UnboundedReceiver<NetworkEvent>;
type SyncSender = UnboundedSender<Vec<u8>>; type SyncSender = UnboundedSender<Vec<u8>>;
type SyncReceiver = UnboundedReceiver<Vec<u8>>; type SyncReceiver = UnboundedReceiver<Vec<u8>>;
/// Start a syncing tokio future.
///
/// This is effectively a stub function being
/// used to test network functionality.
///
/// Expect a full re-write.
pub fn start_sync( pub fn start_sync(
_db: Arc<RwLock<DB>>, _db: Arc<RwLock<DB>>,
network_tx: NetworkSender, _network_tx: NetworkSender,
network_rx: NetworkReceiver, network_rx: NetworkReceiver,
_sync_tx: SyncSender, _sync_tx: SyncSender,
_sync_rx: SyncReceiver, _sync_rx: SyncReceiver,
@ -40,20 +42,9 @@ pub fn start_sync(
}) })
.map_err(|_| panic!("rx failed")); .map_err(|_| panic!("rx failed"));
let poll_future = Interval::new(Instant::now(), Duration::from_secs(2)) /*
.for_each(move |_| { * This is an unfinished stub function.
let msg = OutgoingMessage { */
peer: None,
data: vec![42, 42, 42]
};
network_tx.unbounded_send(msg);
Ok(())
})
.map_err(|_| panic!("send failed"));
let sync_future = poll_future tokio::run(rx_future);
.select(rx_future).map_err(|(err, _)| err)
.and_then(|((), n)| n);
tokio::run(sync_future);
} }