withTransaction

suspend fun <R> RoomDatabase.withTransaction(block: suspend () -> R): R

Wraps a block of code in a write transaction.

This uses useWriterConnection and immediateTransaction internally to provide a familiar API for common code.

Return

The result of the transaction block.

Parameters

block

The block of code to execute within the transaction.