kotlinx.coroutines

Why not use GlobalScope.launch?

♀尐吖头ヾ 提交于 2019-11-30 04:25:21
问题 I read that usage of Globalscope is highly discouraged, here. I have a simple use-case. For every kafka message (let's say a list of Ids) that I receive I have to split it and invoke a rest service simultaneously and wait for it to be done and proceed with other synchronous tasks. There is nothing else is in that application that requires coroutine. In this case, Can I just get away with it? Note: This is not an android application. It's just a kafka stream processor running on server side.

Whats the concept behind a CoroutineScope?

ε祈祈猫儿з 提交于 2019-11-28 07:17:35
问题 After reading the introduction and the javadoc of CoroutineScope I'm still a little confused what the idea behind a CoroutineScope is. The first sentence of the doc "Defines a scope for new coroutines." is not clear to me: Why do my coroutines need a scope? Also, why are standalone coroutine builders deprecated? Why is it better to do this: fun CoroutineScope.produceSquares(): ReceiveChannel<Int> = produce { for (x in 1..5) send(x * x) } instead of fun produceSquares(): ReceiveChannel<Int> =

Update Android Studio Project to Kotlin 1.3

最后都变了- 提交于 2019-11-27 19:38:37
问题 I am attempting to Use Kotlin Coroutine's runBlocking function, but I receive the error that this method was introduced in Kotlin 1.3. So, I tried updating my Android Studio project to use Kotlin 1.3.0 But, when I do that, I get the error: "org.jetbrains.kotlin:kotlin-stdlib-jre7:1.3.0" is unresolved ... What is the recommended way to update my Android Studio project to use Kotlin 1.3? Or is there another method similar to runBlocking that is compatible with Kotlin 1.2.51 ? 回答1: I guess it

Migrate to Kotlin coroutines in Android with Kotlin 1.3

心已入冬 提交于 2019-11-27 05:56:15
问题 What should I change in my build.gradle file or import in classes to use stable coroutine functions in my Android project with Kotlin 1.3 ? Fragment about coroutines in my build.gradle implementation "org.jetbrains.kotlin:kotlin-coroutines-core:$coroutines_version" implementation "org.jetbrains.kotlin:kotlin-coroutines-android:$coroutines_version" Of course I use Android Studio 3.3 Preview 回答1: In build.gradle change a library to implementation 'org.jetbrains.kotlinx:kotlinx-coroutines