diff options
author | Jesse Luehrs <doy@tozt.net> | 2022-01-08 07:55:16 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2022-01-08 07:55:16 -0500 |
commit | 778b1f751a036fc025026be883e336074bde7d9b (patch) | |
tree | a2e301ed4b005dbd530053d2eb8f23fef7b4f556 /src/mutex.rs | |
parent | 22769358621eae3d1e65cff3d402f71b6c1cec4b (diff) | |
download | nbsh-778b1f751a036fc025026be883e336074bde7d9b.tar.gz nbsh-778b1f751a036fc025026be883e336074bde7d9b.zip |
share stdin/stdout/stderr handles among builtins in a pipeline
Diffstat (limited to 'src/mutex.rs')
-rw-r--r-- | src/mutex.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/mutex.rs b/src/mutex.rs index 51192a8..aca5669 100644 --- a/src/mutex.rs +++ b/src/mutex.rs @@ -4,8 +4,10 @@ pub fn new<T>(t: T) -> async_std::sync::Arc<async_std::sync::Mutex<T>> { async_std::sync::Arc::new(async_std::sync::Mutex::new(t)) } -pub fn unwrap<T: std::fmt::Debug>(t: Mutex<T>) -> T { - async_std::sync::Mutex::into_inner( - async_std::sync::Arc::try_unwrap(t).unwrap(), - ) +pub fn unwrap<T: std::fmt::Debug>(t: Mutex<T>) -> Option<T> { + if let Ok(mutex) = async_std::sync::Arc::try_unwrap(t) { + Some(async_std::sync::Mutex::into_inner(mutex)) + } else { + None + } } |