Coroutines
Flow¶
To consume a query as a Flow, add the coroutines extensions artifact as a dependency and use the extension functions it provides:
dependencies {
implementation("app.cash.sqldelight:coroutines-extensions:2.1.0-SNAPSHOT")
}
dependencies {
implementation "app.cash.sqldelight:coroutines-extensions:2.1.0-SNAPSHOT"
}
val players: Flow<List<HockeyPlayer>> =
playerQueries.selectAll()
.asFlow()
.mapToList(Dispatchers.IO)
This flow emits the query result, and emits a new result every time the database changes for that query.