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