46 lines
1.0 KiB
Rust
46 lines
1.0 KiB
Rust
use std::time::Duration;
|
|
|
|
use rdsp::{stream, stream_operators};
|
|
|
|
fn main() {
|
|
let (mut a_tx, a_rx) = stream::stream::<u32>(16);
|
|
let (mut b_tx, b_rx) = stream::stream::<u32>(16);
|
|
|
|
std::thread::spawn(move || {
|
|
let mut k = 0;
|
|
loop {
|
|
std::thread::sleep(Duration::from_millis(800));
|
|
let mut buf = a_tx.write();
|
|
for i in 0..16 {
|
|
buf[i].write(k);
|
|
k += 1;
|
|
}
|
|
buf.swap(16);
|
|
}
|
|
});
|
|
|
|
std::thread::spawn(move || {
|
|
let mut k = 0;
|
|
loop {
|
|
std::thread::sleep(Duration::from_millis(300));
|
|
let mut buf = b_tx.write();
|
|
for i in 0..16 {
|
|
buf[i].write(k);
|
|
k += 1;
|
|
}
|
|
buf.swap(16);
|
|
}
|
|
});
|
|
|
|
let (adder, out) = stream_operators::StreamAdder::new(a_rx, b_rx);
|
|
|
|
{
|
|
loop {
|
|
let x = out.read();
|
|
for i in 0..x.len() {
|
|
println!("{}", x[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|