{"id":21206228,"url":"https://github.com/rtmigo/later_kt","last_synced_at":"2026-04-18T11:05:25.734Z","repository":{"id":60019948,"uuid":"540132601","full_name":"rtmigo/later_kt","owner":"rtmigo","description":"Lightweight asynchronous values for Kotlin. Serves the same purpose as Future, Deferred, Promise. Great for procrastinators","archived":false,"fork":false,"pushed_at":"2022-09-27T01:13:09.000Z","size":143,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"staging","last_synced_at":"2025-07-25T21:44:30.228Z","etag":null,"topics":["async","await","callback","deferred","future","jvm","kotlin","promise"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rtmigo.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}},"created_at":"2022-09-22T19:11:11.000Z","updated_at":"2022-09-23T16:35:42.000Z","dependencies_parsed_at":"2023-01-18T20:05:18.856Z","dependency_job_id":null,"html_url":"https://github.com/rtmigo/later_kt","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rtmigo/later_kt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtmigo%2Flater_kt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtmigo%2Flater_kt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtmigo%2Flater_kt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtmigo%2Flater_kt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rtmigo","download_url":"https://codeload.github.com/rtmigo/later_kt/tar.gz/refs/heads/staging","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rtmigo%2Flater_kt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31966218,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T00:39:45.007Z","status":"online","status_checked_at":"2026-04-18T02:00:07.018Z","response_time":103,"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":["async","await","callback","deferred","future","jvm","kotlin","promise"],"created_at":"2024-11-20T20:54:55.170Z","updated_at":"2026-04-18T11:05:25.714Z","avatar_url":"https://github.com/rtmigo.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Generic badge](https://img.shields.io/badge/Kotlin-1.7-blue.svg)\n![Generic badge](https://img.shields.io/badge/JVM-8-blue.svg)\n\n# [later](https://github.com/rtmigo/later_kt)\n\nA `Later` represents a potential value, that will be available at some\ntime in the future.\n\n- `.value` returns the value, or throws if the value is not set yet\n\n- `.isComplete` returns `true`, if the value is set\n\n- `.await()` waits until the value is set \n\nThe object does not provide concurrency or task queuing. It just fires\ncallbacks as lightly as possible while being thread safe.\n\n- `.onComplete`, `.onSuccess`, `.onError` set callbacks to be run when Later\n  is completed (or run the callbacks immediately, if Later is already completed)\n \n- `.map` maps the value to other Later value\n\nThe object is somewhat similar to \n[Deferred](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/), \n[Future](https://api.dart.dev/be/175791/dart-async/Future-class.html) and\n[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).\n\n# Install\n\n#### settings.gradle.kts\n\n```kotlin\nsourceControl {\n    gitRepository(java.net.URI(\"https://github.com/rtmigo/later_kt.git\")) {\n        producesModule(\"io.github.rtmigo:later\")\n    }\n}\n```\n\n#### build.gradle.kts\n\n```kotlin\ndependencies {\n    implementation(\"io.github.rtmigo:later\") {\n        version { branch = \"staging\" }\n    }\n}\n```\n\n# Basic example\n\n```kotlin\nimport io.github.rtmigo.later.*\n\nfun slowComputation(x: Int): Later\u003cInt\u003e {\n    val result = Later.completable\u003cInt\u003e()\n    thread {\n        // one second later assign value to the returned object\n        sleep(1000)\n        result.value = x * 2   \n    }\n    return result  // return immediately\n}\n\nfun main() {\n    // print \"16\" after one second\n    println(slowComputation(8).await()) \n}\n```\n\n# Creating a Later\n\n`Later.completable\u003cT\u003e()` creates an object without `.value`. The value must be\nassigned before it can be read.\n\n```kotlin\nval a = Later.completable\u003cInt\u003e()\nassert(a.isComplete == false)\n\na.value = 5\n\nassert(a.isComplete == true)\nassert(a.value == 5)\n```\n\nBy calling `Later.value(v)` or `v.asLater()` we create an immutable `Later`, \nwith `v` as value.\n\n```kotlin\nval c = Later.value(7)\n\nassert(c.isComplete == true)\nassert(c.value == 7)\n```\n\n# Async callbacks\n\n```kotlin\n// init\nval a = Later.completable\u003cString\u003e()\na.onSuccess { println(\"What is $it?!\") }\n\n// assigning the value will trigger the callback\na.value = \"love\"\n\n// What is love?!\n```\n\nWe can set multiple callbacks for the same `Later`.\n\n```kotlin\nval a = Later.completable\u003cString\u003e()\na.onSuccess { println(\"What is $it?!\") }\na.onSuccess { println(\"Is $it great?!\") }\na.value = \"Britain\"\n\n// What is Britain?\n// Is Britain great? \n```\n\nWhen value is already set, callbacks are run immediately.\n\n```kotlin\nval iam = Later.value(\"Groot\")\n\na.onSuccess { println(\"You are $it\") }\n\n// You are Groot\n```\n\nWe can use `Unit` as value if all we need is a callback.\n\n```kotlin\nval kindaEvent = mutableLater\u003cUnit\u003e()\nkindaEvent.onSuccess { println(\"Kinda callback\") }\n\nkindaEvent.value = Unit\n\n// Kinda callback\n```\n\n# Mapping\n\nWe can specify later transformations for a later value.\n\n`map` method receives the previous value and returns a new `Later`.\n\n```kotlin\nval a = Later.completable\u003cInt\u003e()                  // a is CompletableLater\u003cInt\u003e\nval b = a.map { \"The number is $it\".asLater() }   // b is Later\u003cString\u003e\nval c = b.map { (it.uppercase()+\"!\").asLater() }  // c is Later\u003cString\u003e\n\n// None of the objects have a value yet. Attempting to read `.value` \n// will throw an exception. But we can assign value to `a`:\n\na.value = 5\n\nprintln(a.value)  // 5\nprintln(b.value)  // The number is 5\nprintln(c.value)  // THE NUMBER IS 5!\n```\n\n# License\n\nCopyright © 2022 Artyom IG \u003cgithub.com/rtmigo\u003e\n\nLicensed under the [MIT License](LICENSE)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frtmigo%2Flater_kt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frtmigo%2Flater_kt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frtmigo%2Flater_kt/lists"}