Small question about coroutines and threads. Is t...
# coroutines
t
Small question about coroutines and threads. Is there a way to make suspend calls made inside another suspending call that will switch context in a defined thread (the one from the root call) Let met try to explain more
Copy code
suspend fun doJob() {
        database.beginTransactionNonExclusive()
        val result = api.doSomethingSuspendRecursive(chunkSize) {
            database.doSomething()
        }
        if (result) {
            database.setTransactionSuccessful()
        }
        database.endTransaction()
    }
The doSomethingSuspendRecursive is a recursive thing so will get X result from a webserver call the lambda X times, then continue until there's no more results. Since the api call part is handled via an channel and workerpool it seems that even if I use withContext(IO) everywhere there will still be thread switchs. I need database consistency so need to run all the db actions in a transaction, but in a transaction all calls needs to be made in the same thread. So the question is it possible to achieve that in that configuration?