use crate::{
consumer::AsyncConsumer,
producer::AsyncProducer,
ring_buffer::{AsyncRbRead, AsyncRbWrite},
};
use ringbuf::ring_buffer::RbRef;
pub async fn async_transfer<T, Rs: RbRef, Rd: RbRef>(
src: &mut AsyncConsumer<T, Rs>,
dst: &mut AsyncProducer<T, Rd>,
count: Option<usize>,
) -> usize
where
Rs::Rb: AsyncRbRead<T>,
Rd::Rb: AsyncRbWrite<T>,
{
let mut actual_count = 0;
loop {
if count.as_ref().map_or(false, |n| actual_count == *n) {
break;
}
actual_count += 1;
match dst
.push(match src.pop().await {
Some(item) => item,
None => break,
})
.await
{
Ok(()) => (),
Err(_item) => break,
};
}
actual_count
}