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:
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
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 handler
Signal.INT.withHandler(
Signal.Handler { println("Received interrupt") }
) {
// Do some stuff that might be interrupted
}
// The previous handler is restored after the block
Signal.TERM.await() // Suspends until the signal is raised
Signal.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.