Tolriq
12/03/2018, 11:59 AMsuspend 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?