kotlinx.coroutines

How to join a Kotlin SupervisorJob

限于喜欢 提交于 2021-02-09 12:09:05
问题 I am trying to process a tree of data objects. Each tree leaf is supposed to be processed through a function using a coroutine. The whole process should be done using a fixed size threadpool. So I came up with this: val node = an instance of WorkspaceEntry (tree structure) val localDispatcher = newFixedThreadPoolContext(16) fun main() { val job = SupervisorJob() val scope = CoroutineScope(localDispatcher + job) handleEntry(node, scope) runBlocking { job.join() } } The handleEntry method

How to join a Kotlin SupervisorJob

假装没事ソ 提交于 2021-02-09 11:59:06
问题 I am trying to process a tree of data objects. Each tree leaf is supposed to be processed through a function using a coroutine. The whole process should be done using a fixed size threadpool. So I came up with this: val node = an instance of WorkspaceEntry (tree structure) val localDispatcher = newFixedThreadPoolContext(16) fun main() { val job = SupervisorJob() val scope = CoroutineScope(localDispatcher + job) handleEntry(node, scope) runBlocking { job.join() } } The handleEntry method

`runBlocking` coroutine builder is not resolved in the project (Other builders are resolved)

☆樱花仙子☆ 提交于 2021-02-08 08:20:52
问题 As the title suggest, the coroutine builder runBlocking is missing in the coroutine liblary I just added in my build.gradle. Funny thing is every other thing appears to be available, GlobalScope , CoroutineScope.launch CoroutineScope.async all present. runBlocking isn't. What am I doing wrong? here is my build.gradle buildscript { ext { ktor_version = "1.1.1" kotlin_version = "1.3.20-eap-52" } dependencies { classpath "org.jetbrains.kotlin:kotlin-frontend-plugin:0.0.44" classpath "org

`runBlocking` coroutine builder is not resolved in the project (Other builders are resolved)

隐身守侯 提交于 2021-02-08 08:20:03
问题 As the title suggest, the coroutine builder runBlocking is missing in the coroutine liblary I just added in my build.gradle. Funny thing is every other thing appears to be available, GlobalScope , CoroutineScope.launch CoroutineScope.async all present. runBlocking isn't. What am I doing wrong? here is my build.gradle buildscript { ext { ktor_version = "1.1.1" kotlin_version = "1.3.20-eap-52" } dependencies { classpath "org.jetbrains.kotlin:kotlin-frontend-plugin:0.0.44" classpath "org

Room with Kotlin-coroutines observe db changes

送分小仙女□ 提交于 2020-07-05 06:04:08
问题 So, I recently started experimentation with coroutines, I switched from Rxjava2 to coroutines, I haven't got a grasp of it yet but still, I ran into a condition where I needed to observe my database change and update the UI corresponding to that. RxJava used to provide me with Flowables, Completeable etc. using that I would be able to observe changes in Db. abstract fun insert(data: SomeData): Long @Query("SELECT * FROM somedata_table") abstract fun getData(): Flowable<List<SomeData>> So here

Unresolved reference: async in Kotlin in 1.3

ε祈祈猫儿з 提交于 2020-06-25 10:50:14
问题 I have multi module kotlin gradle project in github here. One of my sub project introducing-coroutines with build file build.gradle.kts file is here The contents of build.gradle.kts is - import org.jetbrains.kotlin.gradle.dsl.Coroutines import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { java kotlin("jvm") version "1.3.11" } group = "chapter2" version = "1.0-SNAPSHOT" repositories { mavenCentral() } dependencies { compile(kotlin("stdlib-jdk8")) compile("org.jetbrains.kotlinx

Unresolved reference: async in Kotlin in 1.3

心已入冬 提交于 2020-06-25 10:49:20
问题 I have multi module kotlin gradle project in github here. One of my sub project introducing-coroutines with build file build.gradle.kts file is here The contents of build.gradle.kts is - import org.jetbrains.kotlin.gradle.dsl.Coroutines import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { java kotlin("jvm") version "1.3.11" } group = "chapter2" version = "1.0-SNAPSHOT" repositories { mavenCentral() } dependencies { compile(kotlin("stdlib-jdk8")) compile("org.jetbrains.kotlinx