~halzy/waitforit

8eadd3ae69f4b1974eac2cf926100cf9602dd8e9 — Benjamin Halsted a month ago b1e6cc7
status is in it's own task
1 files changed, 12 insertions(+), 9 deletions(-)

M src/main.rs
M src/main.rs => src/main.rs +12 -9
@@ 32,7 32,17 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let buffer_packets = Arc::new(AtomicU32::new(0));

    let read_handle = read_incoming(Arc::clone(&buffer_packets), tx, incoming);
    let send_handle = send_outgoing(buffer_packets, args.delay, rx, outgoing);
    let send_handle = send_outgoing(Arc::clone(&buffer_packets), args.delay, rx, outgoing);

    tokio::spawn(async move {
        let mut interval = tokio::time::interval(Duration::from_secs(1));

        loop {
            interval.tick().await;
            let packet_count = buffer_packets.load(Ordering::SeqCst);
            println!("packets in buffer: {}", packet_count + 1);
        }
    });

    let _ = read_handle.await?;
    let _ = send_handle.await?;


@@ 82,8 92,6 @@ fn read_incoming(

        tx.send((0, header.freeze()))?;

        let mut status_instant = Instant::now();

        //packets
        loop {
            // header


@@ 102,12 110,7 @@ fn read_incoming(
            stream.read_exact(&mut bytes).await?;

            tx.send((header.timestamp, bytes.freeze()))?;
            let previous_buffer_packet = buffer_packets.fetch_add(1, Ordering::SeqCst);

            if status_instant.elapsed() > Duration::from_secs(1) {
                println!("packets in buffer: {}", previous_buffer_packet + 1);
                status_instant = Instant::now();
            }
            buffer_packets.fetch_add(1, Ordering::SeqCst);
        }
    })
}