pub struct Receiver(/* private fields */);Expand description
Receives UNIX signals forwarded through a Signals channel.
Obtained via Signals::subscribe. Use listen to
block until a signal arrives, or try_listen to
poll without blocking.
Implementations§
Source§impl Receiver
impl Receiver
Sourcepub fn listen(&self) -> Result<Signal, SignalError>
pub fn listen(&self) -> Result<Signal, SignalError>
Blocks until a signal is received and returns it.
§Examples
use signal_msg::Signals;
let signals = Signals::new().expect("signal setup failed");
let receiver = signals.subscribe();
match receiver.listen() {
Ok(sig) => println!("received: {}", sig),
Err(e) => eprintln!("channel closed: {}", e),
}§Errors
Returns SignalError::Disconnected if the backing Signals handle
has been dropped and no further signals can arrive.
Sourcepub fn try_listen(&self) -> Result<Option<Signal>, SignalError>
pub fn try_listen(&self) -> Result<Option<Signal>, SignalError>
Returns the next signal if one is immediately available, or None if
the channel is currently empty.
Unlike listen, this method never blocks.
§Examples
use signal_msg::Signals;
let signals = Signals::new().expect("signal setup failed");
let receiver = signals.subscribe();
match receiver.try_listen() {
Ok(Some(sig)) => println!("got signal: {}", sig),
Ok(None) => println!("no signal pending"),
Err(e) => eprintln!("channel closed: {}", e),
}§Errors
Returns SignalError::Disconnected if the backing Signals handle
has been dropped and no further signals can arrive.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Receiver
impl RefUnwindSafe for Receiver
impl Send for Receiver
impl !Sync for Receiver
impl Unpin for Receiver
impl UnsafeUnpin for Receiver
impl UnwindSafe for Receiver
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more