Questions tagged [kotlinx.coroutines]

Library support for Kotlin coroutines in Kotlin/JVM and Kotlin/JS

296 questions
12
votes
2 answers

Compilation error: "-Xcoroutines has no effect: coroutines are enabled anyway in 1.3 and beyond"

When I try to compile my Android app written in Kotlin, I get the following compilation error, and my build fails: w: -Xcoroutines has no effect: coroutines are enabled anyway in 1.3 and beyond How can I fix this?
12
votes
4 answers

Migrate to Kotlin coroutines in Android with Kotlin 1.3

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…
Patryk Kubiak
  • 614
  • 1
  • 4
  • 12
11
votes
2 answers

Kotlin coroutines handle error and implementation

Using coroutines for the first time. Need help. Here is my flow: Presenter wants to login so calls Repository Interface. Repository implements RepositoryInterface. So Repository calls APIInterface. APIInterface is implemented by APIInterfaceImpl.…
Alessandra Maria
  • 215
  • 2
  • 11
11
votes
2 answers

Is NetworkOnMainThreadException valid for a network call in a coroutine?

I'm putting together a simple demo app in Kotlin for Android that retrieves the title of a webpage with Jsoup. I'm conducting the network call using Dispatchers.Main as context. My understanding of coroutines is that if I call launch on the…
Dan 0
  • 737
  • 6
  • 14
11
votes
3 answers

Mocked suspend function returns null in Mockito

I have a suspending functions that I have mocked, using Mockito but it is returning null both projects use 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.0' Example 1 here is my test in which the mock is returning null @Test fun `when gps not…
Mark Gilchrist
  • 1,740
  • 3
  • 22
  • 44
11
votes
1 answer

Integrate Kotlinx coroutines in intelliJ project

I‘m using intellij for a while now. There I work on a javaFx project, which is mainly written in java but I discovered Kotlin to be a nice alternative. Recently I read about coroutines in Kotlin and I just can‘t figure out how to add the Kotlinx…
Punika
  • 275
  • 3
  • 14
11
votes
2 answers

kotlin coroutine throws java.lang.IllegalStateException: Already resumed, but got value Location

I'm quite new to Kotlin coroutine and Android development in general. While playing around to understand how it worked, I faced an error I can't seem to solve. From a basic activity i try to connect to the googleApiClient. The permissions are ok. I…
Shinmen
  • 111
  • 1
  • 4
11
votes
5 answers

how to cap kotlin coroutines maximum concurrency

I've got a Sequence (from File.walkTopDown) and I need to run a long-running operation on each of them. I'd like to use Kotlin best practices / coroutines, but I either get no parallelism, or way too much parallelism and hit a "too many open files"…
10
votes
1 answer

Kotlin coroutines GlobalScope.launch vs runBlocking

Is there any difference between this two approaches? runBlocking { launch(coroutineDispatcher) { // job } } GlobalScope.launch(coroutineDispatcher) { // job }
silent-box
  • 1,392
  • 1
  • 15
  • 32
10
votes
5 answers

can I always use WorkManager instead of coroutines?

I wonder why should I bother with rx or coroutines when there is brilliant solution as WorkManager. But for almost all tutorials they use coroutines so may be WorkManager has disadvantages ?
10
votes
2 answers

Wait For Data Inside a Listener in a Coroutine

I have a coroutine I'd like to fire up at android startup during the splash page. I'd like to wait for the data to come back before I start the next activity. What is the best way to do this? Currently our android is using experimental coroutines…
JPM
  • 8,360
  • 13
  • 73
  • 124
10
votes
3 answers

launch is only available since Kotlin 1.3 and cannot be used in Kotlin 1.2

I'm trying to run the simplest example with coroutines: import kotlinx.coroutines.* fun main() { GlobalScope.launch { delay(1000L) println("${Thread.currentThread().name}: World") } …
Ksenia
  • 2,551
  • 6
  • 23
  • 50
10
votes
2 answers

In kotlin, how do I mock a suspend function that wraps a callback?

Let's say there's an interface with a callback: interface SomeInterface { fun doSomething(arg: String, callback: (Exception?, Long) -> Unit) } which I extend into a suspend function like this: suspend fun SomeInterface.doSomething(arg: String):…
Mircea Nistor
  • 2,868
  • 24
  • 31
9
votes
3 answers

Unresolved reference: async in Kotlin in 1.3

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 …
8
votes
1 answer

How to ignore JobCancellationException?

Recently, I've upgraded Kotlin Coroutines from experimental to 1.1.1 and faced the problem that job.cancel() in new version works differently. Here's the code with Experimental Coroutines: fun > T.runAsync( job:…
Taras Parshenko
  • 534
  • 1
  • 5
  • 15
1
2
3
19 20