{"id":26818794,"url":"https://github.com/karmakrafts/rakii","last_synced_at":"2025-09-23T22:07:02.175Z","repository":{"id":285160342,"uuid":"957243117","full_name":"karmakrafts/RAkII","owner":"karmakrafts","description":"Structured RAII with error handling for Kotlin Multiplatform.","archived":false,"fork":false,"pushed_at":"2025-06-03T00:35:53.000Z","size":3782,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-03T12:53:07.529Z","etag":null,"topics":["gradle","gradle-plugin","kotlin","kotlin-android","kotlin-compiler-plugin","kotlin-js","kotlin-jvm","kotlin-library","kotlin-multiplatform","kotlin-native","library"],"latest_commit_sha":null,"homepage":"https://git.karmakrafts.dev/kk/rakii","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/karmakrafts.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-03-29T22:13:33.000Z","updated_at":"2025-06-03T01:04:04.000Z","dependencies_parsed_at":"2025-06-03T00:53:10.189Z","dependency_job_id":"935e5572-6a09-41a2-ac57-087fff035033","html_url":"https://github.com/karmakrafts/RAkII","commit_stats":null,"previous_names":["karmakrafts/rakii"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/karmakrafts/RAkII","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karmakrafts%2FRAkII","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karmakrafts%2FRAkII/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karmakrafts%2FRAkII/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karmakrafts%2FRAkII/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/karmakrafts","download_url":"https://codeload.github.com/karmakrafts/RAkII/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karmakrafts%2FRAkII/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276655861,"owners_count":25681015,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-23T02:00:09.130Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gradle","gradle-plugin","kotlin","kotlin-android","kotlin-compiler-plugin","kotlin-js","kotlin-jvm","kotlin-library","kotlin-multiplatform","kotlin-native","library"],"created_at":"2025-03-30T05:14:54.709Z","updated_at":"2025-09-23T22:07:02.169Z","avatar_url":"https://github.com/karmakrafts.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RAkII\n\n[![](https://git.karmakrafts.dev/kk/rakii/badges/master/pipeline.svg)](https://git.karmakrafts.dev/kk/rakii/-/pipelines)\n[![](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Frepo.maven.apache.org%2Fmaven2%2Fdev%2Fkarmakrafts%2Frakii%2Frakii-runtime%2Fmaven-metadata.xml\n)](https://git.karmakrafts.dev/kk/rakii/-/packages)\n[![](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Fcentral.sonatype.com%2Frepository%2Fmaven-snapshots%2Fdev%2Fkarmakrafts%2Frakii%2Frakii-runtime%2Fmaven-metadata.xml\n)](https://git.karmakrafts.dev/kk/rakii/-/packages)\n\nRAkII (or Kotlin RAII) is a lightweight runtime library and compiler plugin\nwhich allows using structured RAII with support for error handling in Kotlin Multiplatform.\n\nRAII is a concept commonly known from native languages such as C++ and Rust,\nused for managing the lifetime of memory implicitly.  \nHowever, since Cleaners are not suitable for managing micro-allocations in\na granular manner in Kotlin, this library can be employed to reduce potential for\ncommon errors, resource leaks and double-frees.\n\n### How to use it\n\nSimply add the required repositories to your build configuration, apply the\nGradle plugin and add a dependency on the runtime:\n\nIn your `settings.gradle.kts`:\n\n```kotlin\npluginManagement {\n    repositories {\n        maven(\"https://central.sonatype.com/repository/maven-snapshots\")\n        mavenCentral()\n    }\n}\n\ndependencyResolutionManagement {\n    repositories {\n        maven(\"https://central.sonatype.com/repository/maven-snapshots\")\n        mavenCentral()\n    }\n}\n```\n\nIn your `build.gradle.kts`::\n\n```kotlin\nplugins {\n    id(\"dev.karmakrafts.rakii.rakii-gradle-plugin\") version \"\u003cversion\u003e\"\n}\n\nkotlin {\n    sourceSets {\n        commonMain {\n            dependencies {\n                implementation(\"dev.karmakrafts.rakii:rakii-runtime:\u003cversion\u003e\")\n            }\n        }\n    }\n}\n```\n\n**Note: It is recommended to use Gradle version catalogs which were omitted here for simplification.**\n\n### Usage example\n\n```kotlin\nimport dev.karmakrafts.rakii.Drop\nimport dev.karmakrafts.rakii.deferring\n\nclass Foo : Drop {\n    fun doTheThing() {\n        println(\"I am doing the thing!\")\n    }\n}\n\nclass Bar : Drop {\n    val foo1 by dropping(::Foo)\n\n    // When the initialization of foo2 fails, foo1 will be dropped immediately\n    val foo2 by dropping(::Foo).dropOnAnyError(Bar::foo1)\n\n    fun doTheThings() {\n        foo1.doTheThing()\n        foo2.doTheThing()\n    }\n    \n    fun helloWorld() = deferring {\n        // Tied to the surrounding deferring scope\n        val foo3 by dropping(::Foo)\n        foo3.doTheThing()\n    }\n}\n\nfun main() {\n    Bar().use {\n        // Normally use Bar and its contained Foo instance\n        // Once the use-scope ends, Foo is dropped and Bar is dropped afterward\n        it.doTheThings()\n        it.helloWorld()\n    }\n}\n```\n\n### Performance implications\n\nThe RAkII compiler relies on the fact, that it can fall back to the runtime implementation  \nwhen no optimization is applicable for a certain case.  \nThis means that certain usages of RAII constructs can employ a certain runtime overhead,  \nwhich may not always be desirable.\n\nTake the following use cases of a `deferring` scope as an example:\n\n```kotlin\nimport dev.karmakrafts.rakii.deferring\n\nfun test(closure1: () -\u003e Unit, closure2: () -\u003e Unit): String = deferring {\n    // Can be reached with compiler optimization\n    defer { println(\"HELLO WORLD!\") }\n    // Cannot be reached with compiler optimization\n    defer(closure1)\n    fun test2(): DropDelegate\u003cString, DroppingScope.Owner\u003e {\n        // Cannot be reached with compiler optimization\n        defer { println(\"HELLO WORLD!\") }\n        closure2()\n        // Cannot be reached with compiler optimization\n        return dropping(::println) { \"Testing\" }\n    }\n    // Cannot be reached with compiler optimization\n    val value by test2()\n    // Can be reached with compiler optimization\n    val value2 by dropping(::println) { \"!!!\" }\n    value + value2\n}\n```\n\nAs the above example illustrates as a fact:  \nIf the `DroppingScope` instance is implicitly captured, compiler optimizations may not apply.  \nThere is many more edge cases which are handled by the runtime due to complexity constraints in the compiler.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarmakrafts%2Frakii","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkarmakrafts%2Frakii","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarmakrafts%2Frakii/lists"}