Skip to content

Instantly share code, notes, and snippets.

@masakielastic
Created August 22, 2025 15:34
Show Gist options
  • Select an option

  • Save masakielastic/0e4463e8ae18d16a75dbf149a93a7dfc to your computer and use it in GitHub Desktop.

Select an option

Save masakielastic/0e4463e8ae18d16a75dbf149a93a7dfc to your computer and use it in GitHub Desktop.
Rust Tokio で Ctrl + C の入力を受け付ける

Rust Tokio で Ctrl + C の入力を受け付ける

Cargo.toml

[package]
name = "tokio"
version = "0.1.0"
edition = "2021"

[dependencies]
tokio = { version = "1", features = ["full"] }

src/main.rs

use tokio::signal;

#[tokio::main]
async fn main() {
    println!("waiting for ctrl-c");

    signal::ctrl_c().await.expect("failed to listen for event");

    println!("received ctrl-c event");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment