Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/third_party/rust/tokio/src/signal/   (Firefox Browser Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 2 kB image not shown  

Quelle  mod.rs

  Sprache: Rust
 

//! Asynchronous signal handling for Tokio.
//!
//! Note that signal handling is in general a very tricky topic and should be
//! used with great care. This crate attempts to implement 'best practice' for
//! signal handling, but it should be evaluated for your own applications' needs
//! to see if it's suitable.
//!
//! There are some fundamental limitations of this crate documented on the OS
//! specific structures, as well.
//!
//! # Examples
//!
//! Print on "ctrl-c" notification.
//!
//! ```rust,no_run
//! use tokio::signal;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//!     signal::ctrl_c().await?;
//!     println!("ctrl-c received!");
//!     Ok(())
//! }
//! ```
//!
//! Wait for `SIGHUP` on Unix
//!
//! ```rust,no_run
//! # #[cfg(unix)] {
//! use tokio::signal::unix::{signal, SignalKind};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//!     // An infinite stream of hangup signals.
//!     let mut stream = signal(SignalKind::hangup())?;
//!
//!     // Print whenever a HUP signal is received
//!     loop {
//!         stream.recv().await;
//!         println!("got signal HUP");
//!     }
//! }
//! # }
//! ```
use crate::sync::watch::Receiver;
use std::task::{Context, Poll};

#[cfg(feature = "signal")]
mod ctrl_c;
#[cfg(feature = "signal")]
pub use ctrl_c::ctrl_c;

pub(cratemod registry;

mod os {
    #[cfg(unix)]
    pub(crateuse super::unix::{OsExtraData, OsStorage};

    #[cfg(windows)]
    pub(crateuse super::windows::{OsExtraData, OsStorage};
}

pub mod unix;
pub mod windows;

mod reusable_box;
use self::reusable_box::ReusableBoxFuture;

#[derive(Debug)]
struct RxFuture {
    inner: ReusableBoxFuture<Receiver<()>>,
}

async fn make_future(mut rx: Receiver<()>) -> Receiver<()> {
    rx.changed().await.expect("signal sender went away");
    rx
}

impl RxFuture {
    fn new(rx: Receiver<()>) -> Self {
        Self {
            inner: ReusableBoxFuture::new(make_future(rx)),
        }
    }

    async fn recv(&mut self) -> Option<()> {
        use crate::future::poll_fn;
        poll_fn(|cx| self.poll_recv(cx)).await
    }

    fn poll_recv(&mut self, cx: &mut Context<'_>) -> Poll<Option<()>> {
        match self.inner.poll(cx) {
            Poll::Pending => Poll::Pending,
            Poll::Ready(rx) => {
                self.inner.set(make_future(rx));
                Poll::Ready(Some(()))
            }
        }
    }
}

Messung V0.5 in Prozent
C=45 H=93 G=72

¤ Dauer der Verarbeitung: 0.8 Sekunden  (vorverarbeitet am  2026-06-18) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.