From a1599df126003db619649828dcc971f31ab2d1c6 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Wed, 13 Jul 2022 02:48:11 -0400 Subject: [PATCH] Update the processor for the previous commit --- processor/src/lib.rs | 4 ++-- processor/src/tests/mod.rs | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/processor/src/lib.rs b/processor/src/lib.rs index fe427dfe..ee7ad1fa 100644 --- a/processor/src/lib.rs +++ b/processor/src/lib.rs @@ -1,4 +1,4 @@ -use std::{marker::Send, collections::HashMap}; +use std::{marker::Send, io::Cursor, collections::HashMap}; use async_trait::async_trait; use thiserror::Error; @@ -17,7 +17,7 @@ pub enum NetworkError {} #[async_trait] pub trait Network: Send { - async fn round(&mut self, data: Vec) -> Result>, NetworkError>; + async fn round(&mut self, data: Vec) -> Result>>, NetworkError>; } #[derive(Clone, Error, Debug)] diff --git a/processor/src/tests/mod.rs b/processor/src/tests/mod.rs index 051ecad6..89bf069f 100644 --- a/processor/src/tests/mod.rs +++ b/processor/src/tests/mod.rs @@ -1,4 +1,4 @@ -use std::{sync::{Arc, RwLock}, collections::HashMap}; +use std::{io::Cursor, sync::{Arc, RwLock}, collections::HashMap}; use async_trait::async_trait; @@ -11,7 +11,7 @@ struct LocalNetwork { i: u16, size: u16, round: usize, - rounds: Arc>>>> + rounds: Arc>>>>> } impl LocalNetwork { @@ -27,13 +27,13 @@ impl LocalNetwork { #[async_trait] impl Network for LocalNetwork { - async fn round(&mut self, data: Vec) -> Result>, NetworkError> { + async fn round(&mut self, data: Vec) -> Result>>, NetworkError> { { let mut rounds = self.rounds.write().unwrap(); if rounds.len() == self.round { rounds.push(HashMap::new()); } - rounds[self.round].insert(self.i, data); + rounds[self.round].insert(self.i, Cursor::new(data)); } while { @@ -43,7 +43,8 @@ impl Network for LocalNetwork { tokio::task::yield_now().await; } - let res = self.rounds.try_read().unwrap()[self.round].clone(); + let mut res = self.rounds.try_read().unwrap()[self.round].clone(); + res.remove(&self.i); self.round += 1; Ok(res) }