emKt

Lightweight signal abstraction for emitting typed events and connecting synchronous handlers. Includes connection handles and a global named-signal registry for simple, minimal event routing.

Android JVMJVMKotlin/NativeWasmJS
GitHub stars1
AuthorsOmyDaGreat
Open issues6
LicenseMIT License
Creation date5 months ago

Last activityabout 2 months ago
Latest release1.0.1 (4 months ago)

= emKt — A lightweight Kotlin Multiplatform Signal library :toc: left :toclevels: 3 :source-highlighter: highlightjs :icons: font

A small, idiomatic Kotlin Multiplatform library that provides a Signal abstraction for emitting typed events and connecting handlers across platforms (JVM, Android, JS, WASM, Native).

== Overview

emKt offers a minimal signaling utility inspired by Godot's signals. It is implemented with a small, platform-agnostic API that makes it easy to emit values and connect synchronous handlers.

Key concepts:

  • Signal — a simple event source that emits values of type T.
  • Connection — a small handle that can disconnect a handler created by Signal.connect().
  • Signals — a global registry to register and retrieve named signals.

== Features

  • Kotlin Multiplatform — use the library on JVM, Android, JavaScript, WASM and Native targets.
  • Small API surface — easy to read and integrate.

== Quick start

=== Add the dependency

emKt is configured for Maven Central publishing in this template. Replace <version> with the current release (check repository tags/releases):

[source,groovy]

// Gradle (Kotlin DSL) implementation("xyz.malefic:emkt:")

[source,xml]

xyz.malefic emkt <version> ----

== API examples

Below are common usage patterns. Import the package by adding the following import in your Kotlin files: import xyz.malefic.emkt.*

=== Basic Signal usage

[source,kotlin]

// Create or retrieve a named Signal (type parameter defines the payload type) val signal = Signals.register("mySignal")

// Connect a synchronous handler. Returns a Connection which can be disconnected val conn = signal.connect { value -> println("Received: $value") }

// Emit values synchronously to all connected handlers signal.emit("hello")

// Later, disconnect the handler conn.disconnect()

=== Multiple handlers and clearing signals

[source,kotlin]

val s = Signals.register("counter") val a = s.connect { v -> println("A: $v") } val b = s.connect { v -> println("B: $v") }

s.emit(1)

// Disconnect individual connections a.disconnect()

// Clear all registered signals Signals.clear()

== Design notes

  • The implementation is intentionally small: signals maintain a list of handlers and call them synchronously on emit().
  • Signals provides a simple global registry useful for application-level event routing. Call Signals.clear() in tests or when you want to drop all registrations.

== Building & testing

Prerequisites:

  • JDK 11+
  • Gradle 8+

Build the library (all targets configured in this repo):

[source,bash]

./gradlew build

Run the library tests (common tests plus platform tests as configured):

[source,bash]

./gradlew allTests

Generate Dokka documentation:

[source,bash]

./gradlew dokkaGenerate

== Publishing

This repository includes a pre-configured publishing setup. See library/build.gradle.kts and gradle.properties for coordinates and signing configuration. To publish manually (local or to Maven Central when credentials are set):

[source,bash]

./gradlew publishToMavenCentral

For automated publishing the project expects GitHub Secrets for GPG and Sonatype credentials — see gradle.properties and repository workflows for details.

== Contributing

Contributions are welcome. Suggested workflow:

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new behavior (commonTest where possible)
  4. Open a pull request

Please follow Kotlin style and keep changes focused and tested.

== License

This project is published under the MIT License — see the LICENSE file for details.

== Contact / Maintainer

Maintainer: Om Gupta (OmyDaGreat) — ogupta4242@gmail.com

Android JVMJVMKotlin/NativeWasmJS
GitHub stars1
AuthorsOmyDaGreat
Open issues6
LicenseMIT License
Creation date5 months ago

Last activityabout 2 months ago
Latest release1.0.1 (4 months ago)

= emKt — A lightweight Kotlin Multiplatform Signal library :toc: left :toclevels: 3 :source-highlighter: highlightjs :icons: font

A small, idiomatic Kotlin Multiplatform library that provides a Signal abstraction for emitting typed events and connecting handlers across platforms (JVM, Android, JS, WASM, Native).

== Overview

emKt offers a minimal signaling utility inspired by Godot's signals. It is implemented with a small, platform-agnostic API that makes it easy to emit values and connect synchronous handlers.

Key concepts:

  • Signal — a simple event source that emits values of type T.
  • Connection — a small handle that can disconnect a handler created by Signal.connect().
  • Signals — a global registry to register and retrieve named signals.

== Features

  • Kotlin Multiplatform — use the library on JVM, Android, JavaScript, WASM and Native targets.
  • Small API surface — easy to read and integrate.

== Quick start

=== Add the dependency

emKt is configured for Maven Central publishing in this template. Replace <version> with the current release (check repository tags/releases):

[source,groovy]

// Gradle (Kotlin DSL) implementation("xyz.malefic:emkt:")

[source,xml]

xyz.malefic emkt <version> ----

== API examples

Below are common usage patterns. Import the package by adding the following import in your Kotlin files: import xyz.malefic.emkt.*

=== Basic Signal usage

[source,kotlin]

// Create or retrieve a named Signal (type parameter defines the payload type) val signal = Signals.register("mySignal")

// Connect a synchronous handler. Returns a Connection which can be disconnected val conn = signal.connect { value -> println("Received: $value") }

// Emit values synchronously to all connected handlers signal.emit("hello")

// Later, disconnect the handler conn.disconnect()

=== Multiple handlers and clearing signals

[source,kotlin]

val s = Signals.register("counter") val a = s.connect { v -> println("A: $v") } val b = s.connect { v -> println("B: $v") }

s.emit(1)

// Disconnect individual connections a.disconnect()

// Clear all registered signals Signals.clear()

== Design notes

  • The implementation is intentionally small: signals maintain a list of handlers and call them synchronously on emit().
  • Signals provides a simple global registry useful for application-level event routing. Call Signals.clear() in tests or when you want to drop all registrations.

== Building & testing

Prerequisites:

  • JDK 11+
  • Gradle 8+

Build the library (all targets configured in this repo):

[source,bash]

./gradlew build

Run the library tests (common tests plus platform tests as configured):

[source,bash]

./gradlew allTests

Generate Dokka documentation:

[source,bash]

./gradlew dokkaGenerate

== Publishing

This repository includes a pre-configured publishing setup. See library/build.gradle.kts and gradle.properties for coordinates and signing configuration. To publish manually (local or to Maven Central when credentials are set):

[source,bash]

./gradlew publishToMavenCentral

For automated publishing the project expects GitHub Secrets for GPG and Sonatype credentials — see gradle.properties and repository workflows for details.

== Contributing

Contributions are welcome. Suggested workflow:

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new behavior (commonTest where possible)
  4. Open a pull request

Please follow Kotlin style and keep changes focused and tested.

== License

This project is published under the MIT License — see the LICENSE file for details.

== Contact / Maintainer

Maintainer: Om Gupta (OmyDaGreat) — ogupta4242@gmail.com