Add doc comments
This commit is contained in:
parent
9282527cb9
commit
e659213fc1
|
@ -4,24 +4,43 @@ use std::sync::{
|
||||||
Arc,
|
Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Controls the execution of nushell code.
|
||||||
|
///
|
||||||
|
/// For now, the only purpose of this struct is to check for interruption (ctrl+c or SIGINT).
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Interrupt {
|
pub struct Interrupt {
|
||||||
interrupt: Option<Arc<AtomicBool>>,
|
interrupt: Option<Arc<AtomicBool>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Interrupt {
|
impl Interrupt {
|
||||||
|
/// An [`Interrupt`] that is not hooked up to any event/interrupt source.
|
||||||
|
///
|
||||||
|
/// So, this [`Interrupt`] will never be triggered.
|
||||||
pub const EMPTY: Self = Interrupt { interrupt: None };
|
pub const EMPTY: Self = Interrupt { interrupt: None };
|
||||||
|
|
||||||
|
/// Create a new [`Interrupt`] with `ctrlc` as the interrupt source.
|
||||||
|
///
|
||||||
|
/// Once `ctrlc` is set to `true`, [`check`](Self::check) will error
|
||||||
|
/// and [`triggered`](Self::triggered) will return `true`.
|
||||||
pub fn new(ctrlc: Arc<AtomicBool>) -> Self {
|
pub fn new(ctrlc: Arc<AtomicBool>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
interrupt: Some(ctrlc),
|
interrupt: Some(ctrlc),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create [`Interrupt`] that is not hooked up to any event/interrupt source.
|
||||||
|
///
|
||||||
|
/// So, the returned [`Interrupt`] will never be triggered.
|
||||||
|
///
|
||||||
|
/// This should only be used in test code, or if the stream/iterator being created
|
||||||
|
/// already has an [`Interrupt`].
|
||||||
pub const fn empty() -> Self {
|
pub const fn empty() -> Self {
|
||||||
Self::EMPTY
|
Self::EMPTY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns an `Err` if this [`Interrupt`] has been triggered.
|
||||||
|
///
|
||||||
|
/// Otherwise, returns `Ok`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn check(&self, span: Span) -> Result<(), ShellError> {
|
pub fn check(&self, span: Span) -> Result<(), ShellError> {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -37,6 +56,7 @@ impl Interrupt {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns whether this [`Interrupt`] has been triggered.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn triggered(&self) -> bool {
|
pub fn triggered(&self) -> bool {
|
||||||
self.interrupt
|
self.interrupt
|
||||||
|
|
Loading…
Reference in New Issue
Block a user