Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

132
Visualizações
Does Android Room wait for withTransaction block to finish before proceeding to next line
class MyViewModel(private val db: AppDatabase): ViewModel() {

    suspend fun insertAndRead(pages: List<Page>) {
        db.withTransaction {
            db.pageDao().insertAll(pages)    
        }
        val pagesInserted = db.pageDao().selectAll()
    }
}

I'm curious about the Room handles the withTransaction block.

Let's say with the code example above. Does Room wait for the withTransaction block to finish running, then go to then next line?

Or it simply runs the withTransaction block inside a coroutine, then starting the next line immediately without waiting for the withTransaction block to complete?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

withTransaction() is a suspend function. Suspend functions generally wait by suspending, they are synchronous to their callers, they don't schedule asynchronous operations.

So the answer is: yes, it waits for the inner block to finish executing.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda