A Kotlin Multiplatform library that aggregates platform specific system signals (e.g. SIGINT, SIGTERM, etc.) into a clean common API.
- 🔗 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:
jvmlinuxX64linuxArm64mingwX64- Android native
androidNativeX64androidNativeArm64androidNativeX86androidNativeArm32
- Apple targets (untested)
macosX64macosArm64iosX64iosArm64iosSimulatorArm64watchosX64watchosArm64watchosSimulatorArm64watchosDeviceArm64watchosArm32tvosX64tvosArm64tvosSimulatorArm64
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>Signal.ABRT.handle { println("Received abort") } // Returns the previous handlerSignal.INT.withHandler(
Signal.Handler { println("Received interrupt") }
) {
// Do some stuff that might be interrupted
}
// The previous handler is restored after the blockSignal.TERM.await() // Suspends until the signal is raisedSignal.SEGV.raise()If you have any feedback or ideas, feel free to open an issue or create a pull request.
This project is licensed under the MIT License.