pub mod command_is_executing; pub mod errors; pub mod input; pub mod ipc; pub mod os_input_output; pub mod pty_bus; pub mod screen; pub mod setup; pub mod utils; pub mod wasm_vm; use crate::panes::PaneId; use crate::server::ServerInstruction; use async_std::task_local; use errors::{get_current_ctx, ErrorContext}; use std::cell::RefCell; use std::sync::mpsc; /// An [MPSC](mpsc) asynchronous channel with added error context. pub type ChannelWithContext = ( mpsc::Sender<(T, ErrorContext)>, mpsc::Receiver<(T, ErrorContext)>, ); /// An [MPSC](mpsc) synchronous channel with added error context. pub type SyncChannelWithContext = ( mpsc::SyncSender<(T, ErrorContext)>, mpsc::Receiver<(T, ErrorContext)>, ); /// Wrappers around the two standard [MPSC](mpsc) sender types, [`mpsc::Sender`] and [`mpsc::SyncSender`], with an additional [`ErrorContext`]. #[derive(Clone)] pub enum SenderType { /// A wrapper around an [`mpsc::Sender`], adding an [`ErrorContext`]. Sender(mpsc::Sender<(T, ErrorContext)>), /// A wrapper around an [`mpsc::SyncSender`], adding an [`ErrorContext`]. SyncSender(mpsc::SyncSender<(T, ErrorContext)>), } /// Sends messages on an [MPSC](std::sync::mpsc) channel, along with an [`ErrorContext`], /// synchronously or asynchronously depending on the underlying [`SenderType`]. #[derive(Clone)] pub struct SenderWithContext { sender: SenderType, } impl SenderWithContext { pub fn new(sender: SenderType) -> Self { Self { sender } } /// Sends an event, along with the current [`ErrorContext`], on this /// [`SenderWithContext`]'s channel. pub fn send(&self, event: T) -> Result<(), mpsc::SendError<(T, ErrorContext)>> { let err_ctx = get_current_ctx(); match self.sender { SenderType::Sender(ref s) => s.send((event, err_ctx)), SenderType::SyncSender(ref s) => s.send((event, err_ctx)), } } } unsafe impl Send for SenderWithContext {} unsafe impl Sync for SenderWithContext {} thread_local!( /// A key to some thread local storage (TLS) that holds a representation of the thread's call /// stack in the form of an [`ErrorContext`]. pub static OPENCALLS: RefCell = RefCell::default() ); task_local! { /// A key to some task local storage that holds a representation of the task's call /// stack in the form of an [`ErrorContext`]. static ASYNCOPENCALLS: RefCell = RefCell::default() }