use crate::{errors::LisaError, input::stdin::os_specific_apis::read_non_blocking_stdin};
use parking_lot::Mutex;
use std::io::{Error as IoError, Stdin};
use tokio::sync::mpsc::Receiver as BoundedReceiver;
pub trait ReadProvider: Send + Sync + Sized {
fn non_blocking_read(&self) -> Result<String, LisaError>;
}
impl ReadProvider for Stdin {
fn non_blocking_read(&self) -> Result<String, LisaError> {
read_non_blocking_stdin()
}
}
impl ReadProvider for Mutex<BoundedReceiver<String>> {
fn non_blocking_read(&self) -> Result<String, LisaError> {
self.lock()
.try_recv()
.map_err(|cause| LisaError::IOError(IoError::other(cause)))
}
}