use crate::{
global::RC,
vm::alpha::io::{Channel, OutputChannel},
};
use nar_dev_utils::RefCount;
use navm::output::Output;
use std::collections::VecDeque;
#[derive(Debug, Clone, Default)]
pub struct ChannelOut {
cached_outputs: VecDeque<Output>,
}
impl ChannelOut {
pub fn new() -> Self {
Self {
cached_outputs: VecDeque::new(),
}
}
pub fn fetch(&mut self) -> Option<Output> {
self.cached_outputs.pop_front()
}
pub fn fetch_rc(this: &mut RC<Self>) -> Option<Output> {
this.mut_().fetch()
}
}
impl Channel for ChannelOut {
fn need_remove(&self) -> bool {
false
}
}
impl OutputChannel for ChannelOut {
fn next_output(&mut self, outputs: &[Output]) {
self.cached_outputs.extend(outputs.iter().cloned());
}
}
impl Channel for RC<ChannelOut> {
fn need_remove(&self) -> bool {
self.get_().need_remove()
}
}
impl OutputChannel for RC<ChannelOut> {
fn next_output(&mut self, outputs: &[Output]) {
self.mut_().next_output(outputs)
}
}