https://kotlinlang.org logo
#coroutines
Title
# coroutines
m

mbonnin

06/11/2019, 12:38 PM
I have a bunch of code that (schematically) does this:
Copy code
GlobalScope.launch {
            val deferred = CompletableDeferred<Unit>()

            Thread {
                val result = doSomething()
                if (result == SUCCESS) {
                    deferred.complete(Unit)
                } else {
                    deferred.completeExceptionally(Exception("oopps"))
                }
            }.start()

            deferred.await()
        }
This is working well in the nominal case but in the error case, nothing in the backstack indicates where the await() is done. Is there any chance I could have that info somehow to help debug a crash ?
The
await
are basically scattered in all the codebase and the thread is the okhttp threadpool. I get a crash from firebase reporting but no clue where the missing try/catch is.
It might be something else but it really looks like I'm missing a try/catch somewhere. Having that info in the crash report would help a lot
g

gildor

06/11/2019, 1:41 PM
Okay, this coroutine adapter looks fine
First of all, did you enable coroutines debug mode? It allows to restore suspension points stack
Could you share some example of stack trace?
m

mbonnin

06/11/2019, 1:43 PM
ah, cool, didn't know about that. That might help but I'm afraid it won't be enough as so far I haven't been able to reproduce the crash so I was hoping to get some more logs from firebase.
4 Views