aboutsummaryrefslogtreecommitdiffstats
path: root/src/common/mod.rs
diff options
context:
space:
mode:
authorKyle Sutherland-Cash <kyle.sutherlandcash@gmail.com>2021-05-08 04:32:31 -0700
committerKyle Sutherland-Cash <kyle.sutherlandcash@gmail.com>2021-05-08 04:32:31 -0700
commit9a3e8bcb84caa0fd103b6d9c365fb97690c1c5ea (patch)
treeb866062e2880088fce6770553db564721876fc39 /src/common/mod.rs
parentREADME: shortening + add explanation (#470) (diff)
downloadsl0ppij-9a3e8bcb84caa0fd103b6d9c365fb97690c1c5ea.tar.gz
sl0ppij-9a3e8bcb84caa0fd103b6d9c365fb97690c1c5ea.tar.xz
sl0ppij-9a3e8bcb84caa0fd103b6d9c365fb97690c1c5ea.zip
First round of merging against server-client and color stuff
Diffstat (limited to 'src/common/mod.rs')
-rw-r--r--src/common/mod.rs65
1 files changed, 2 insertions, 63 deletions
diff --git a/src/common/mod.rs b/src/common/mod.rs
index 6061f1a6..c91e1e05 100644
--- a/src/common/mod.rs
+++ b/src/common/mod.rs
@@ -3,73 +3,12 @@ pub mod errors;
pub mod input;
pub mod ipc;
pub mod os_input_output;
-pub mod pty_bus;
+pub mod pty;
pub mod screen;
pub mod setup;
+pub mod thread_bus;
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<T> = (
- mpsc::Sender<(T, ErrorContext)>,
- mpsc::Receiver<(T, ErrorContext)>,
-);
-/// An [MPSC](mpsc) synchronous channel with added error context.
-pub type SyncChannelWithContext<T> = (
- 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<T: Clone> {
- /// 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<T: Clone> {
- sender: SenderType<T>,
-}
-
-impl<T: Clone> SenderWithContext<T> {
- pub fn new(sender: SenderType<T>) -> 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<T: Clone> Send for SenderWithContext<T> {}
-unsafe impl<T: Clone> Sync for SenderWithContext<T> {}
-
-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<ErrorContext> = 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<ErrorContext> = RefCell::default()
-}