diff options
| author | Kunal Mohan <kunalmohan99@gmail.com> | 2021-04-09 21:52:46 +0530 |
|---|---|---|
| committer | Kunal Mohan <kunalmohan99@gmail.com> | 2021-04-12 20:33:22 +0530 |
| commit | 380d69978ce0adde07f63ef8c746d7f32b2d2e38 (patch) | |
| tree | 876f068616f7e46c41b9364f138ebb001dabed3b /src/common/errors.rs | |
| parent | fix(performance): remove unnecessary allocations from pty (#264) (diff) | |
| download | sl0ppij-380d69978ce0adde07f63ef8c746d7f32b2d2e38.tar.gz sl0ppij-380d69978ce0adde07f63ef8c746d7f32b2d2e38.tar.xz sl0ppij-380d69978ce0adde07f63ef8c746d7f32b2d2e38.zip | |
make error model more autonomous
Diffstat (limited to 'src/common/errors.rs')
| -rw-r--r-- | src/common/errors.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/common/errors.rs b/src/common/errors.rs index 9801428c..d0b748ab 100644 --- a/src/common/errors.rs +++ b/src/common/errors.rs @@ -1,7 +1,7 @@ //! Error context system based on a thread-local representation of the call stack, itself based on //! the instructions that are sent between threads. -use super::{AppInstruction, OPENCALLS}; +use super::{AppInstruction, ASYNCOPENCALLS, OPENCALLS}; use crate::pty_bus::PtyInstruction; use crate::screen::ScreenInstruction; @@ -72,6 +72,12 @@ pub fn handle_panic( } } +pub fn get_current_ctx() -> ErrorContext { + ASYNCOPENCALLS + .try_with(|ctx| *ctx.borrow()) + .unwrap_or_else(|_| OPENCALLS.with(|ctx| *ctx.borrow())) +} + /// A representation of the call stack. #[derive(Clone, Copy)] pub struct ErrorContext { @@ -95,7 +101,9 @@ impl ErrorContext { break; } } - OPENCALLS.with(|ctx| *ctx.borrow_mut() = *self); + ASYNCOPENCALLS + .try_with(|ctx| *ctx.borrow_mut() = *self) + .unwrap_or_else(|_| OPENCALLS.with(|ctx| *ctx.borrow_mut() = *self)); } } |
