8000 GitHub - Jojo4GH/ksignal: Kotlin Multiplatform library for system signals
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Kotlin Multiplatform library for system signals

License

Notifications You must be signed in to change notification settings

Jojo4GH/ksignal

Repository files navigation

Ksignal

Maven Central GitHub

Kotlin Multiplatform JVM Platform Linux Native Windows Native Android Native macOS Native iOS Native watchOS Native tvOS Native

A Kotlin Multiplatform library that aggregates platform specific system signals (e.g. SIGINT, SIGTERM, etc.) into a clean common API.

⭐️ Main Features

  • 🔗 Unified API: A single API for handling signals across all supported platforms.
  • 🚩 Platform Support: Supports almost all platforms, including JVM and Native platforms.
  • Zero Dependencies: No external dependencies, just pure Kotlin.
  • 💎 Idiomatic Kotlin: Uses Kotlin's language features like lambdas and suspending functions to provide a clean and idiomatic API.

Currently ksignal supports the following targets:

  • jvm
  • linuxX64
  • linuxArm64
  • mingwX64
  • Android native
    • androidNativeX64
    • androidNativeArm64
    • androidNativeX86
    • androidNativeArm32
  • Apple targets (untested)
    • macosX64
    • macosArm64
    • iosX64
    • iosArm64
    • iosSimulatorArm64
    • watchosX64
    • watchosArm64
    • watchosSimulatorArm64
    • watchosDeviceArm64
    • watchosArm32
    • tvosX64
    • tvosArm64
    • tvosSimulatorArm64

🛠️ Installation

The ksignal dependency is available on Maven Central and can be added to your common source set. Just replace $ksignalVersion with the latest version.

Gradle - Kotlin DSL
implementation("de.jonasbroeckmann.ksignal:ksignal:$ksignalVersion")
Gradle - Groovy DSL
implementation "de.jonasbroeckmann.ksignal:ksignal:$ksignalVersion"
Maven
<dependencies>
    <dependency>
        <groupId>de.jonasbroeckmann.ksignal</groupId>
        <artifactId>ksignal</artifactId>
        <version>$ksignalVersion</version>
    </dependency>
</dependencies>

🚀 Usage

Handle signals

Signal.ABRT.handle { println("Received abort") } // Returns the previous handler

Temporarily handle signals

Signal.INT.withHandler(
    Signal.Handler { println("Received interrupt") }
) {
    // Do some stuff that might be interrupted
}
// The previous handler is restored after the block

Await signals

Signal.TERM.await() // Suspends until the signal is raised

Raise signals

Signal.SEGV.raise()

🚧 Contributing

If you have any feedback or ideas, feel free to open an issue or create a pull request.

📄 License

This project is licensed under the MIT License.

0