{"id":18558994,"url":"https://github.com/linux-china/kotlin-coroutine-demo","last_synced_at":"2025-04-10T01:33:08.645Z","repository":{"id":136595655,"uuid":"157461298","full_name":"linux-china/kotlin-coroutine-demo","owner":"linux-china","description":"Kotlin Coroutines demo","archived":false,"fork":false,"pushed_at":"2024-10-30T09:57:27.000Z","size":555,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T02:51:10.789Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linux-china.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2018-11-13T23:31:41.000Z","updated_at":"2024-10-30T09:57:31.000Z","dependencies_parsed_at":"2024-11-06T21:44:46.324Z","dependency_job_id":"51c24da7-9a0f-4422-b5a3-e819006274b9","html_url":"https://github.com/linux-china/kotlin-coroutine-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linux-china%2Fkotlin-coroutine-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linux-china%2Fkotlin-coroutine-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linux-china%2Fkotlin-coroutine-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linux-china%2Fkotlin-coroutine-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linux-china","download_url":"https://codeload.github.com/linux-china/kotlin-coroutine-demo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248140798,"owners_count":21054353,"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","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":[],"created_at":"2024-11-06T21:41:48.059Z","updated_at":"2025-04-10T01:33:03.635Z","avatar_url":"https://github.com/linux-china.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"Kotlin Coroutine Demo\n=====================\n\n# Vocabulary\n\n* Coroutine: light thread\n* CoroutineContext: Persistent context for the coroutine\n* Channel: Deferred values provide a convenient way to transfer a single value between coroutines: SendChannel \u0026 ReceiveChannel\n```\nval channel = Channel\u003cInt\u003e()\n```\n* Fan-out: Multiple coroutines may receive from the same channel\n* Fan-in: Multiple coroutines may send to the same channel\n* Actors: An actor is a combination of a coroutine, the state(confined and encapsulated into this coroutine), and a channel to communicate with other coroutines\n* Mutex: Mutual exclusion, mutex.withLock { counter++ }\n* select: Select expression makes it possible to await multiple suspending functions simultaneously and select the first one that becomes available.\n\n# Convert between Coroutines and Reactive\n\n* Kotlin Coroutines Service with Flow\n\n```kotlin\ninterface UserService {\n    suspend fun getNick(): String\n    suspend fun getNickById(id: Int): String\n    fun getAllNames(): Flow\u003cString\u003e\n}\n```\n\n* Kotlin compiled to Java. Continuation as last param of suspend method\n\n```\npublic interface UserService {\n  public abstract java.lang.Object getNick(kotlin.coroutines.Continuation\u003c? super java.lang.String\u003e);\n  public abstract java.lang.Object getNickById(int, kotlin.coroutines.Continuation\u003c? super java.lang.String\u003e);\n  public abstract kotlinx.coroutines.flow.Flow\u003cjava.lang.String\u003e getAllNames();\n}\n```\n\n# References\n\n* Unit Testing Channels \u0026 Flows: https://speakerdeck.com/heyitsmohit/unit-testing-channels-and-flows-droidcon-americas\n* Introduction to Coroutines and Channels: https://play.kotlinlang.org/hands-on/Introduction%20to%20Coroutines%20and%20Channels/01_Introduction\n* Kotlin Coroutines: https://github.com/Kotlin/kotlinx.coroutines\n* Kotlin Flow: https://kotlinlang.org/docs/reference/coroutines/flow.html\n* AtomicFU: https://github.com/Kotlin/kotlinx.atomicfu\n* Kotlin Coroutines 1.5: GlobalScope Marked as Delicate, Refined Channels API, and More: https://blog.jetbrains.com/kotlin/2021/05/kotlin-coroutines-1-5-0-released/\n* Understanding Kotlin Coroutines: https://reflectoring.io/understanding-kotlin-coroutines-tutorial/\n* Running Kotlin coroutines on Project Loom's virtual threads: https://kt.academy/article/dispatcher-loom\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinux-china%2Fkotlin-coroutine-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinux-china%2Fkotlin-coroutine-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinux-china%2Fkotlin-coroutine-demo/lists"}