Zoltan Demant
09/04/2022, 4:37 AMZoltan Demant
09/04/2022, 4:40 AM'*Suspension functions can be called only within coroutine body'
which is expected.
final override suspend fun matching(
specification: S,
): List<T> {
return execute {
val ids = matching(specification).executeAsList()
cache.get(ids) //suspend call
}
}
But this does not.
final override suspend fun all(): List<T> {
return execute {
all()
.executeAsList()
.chunked(MAX_QUERY_SIZE)
.flatMap { ids -> cache.get(ids) } //suspend call
}
}
The execute function used in both places is this:
private suspend inline fun <R> execute(
crossinline action: ProgressionDatabase.() -> R,
): R {
return withContext(IO) {
val database = store.database()
database.action()
}
}
I cant tell why its possible to call the suspend function in one place, but not the other.Zoltan Demant
09/04/2022, 4:50 AMsuspend
declaration before the lambda in order for it to be able to call other suspend functions? And in either case really, I still dont understand why one execute block is able to call a suspend function, whereas the other is not?ephemient
09/04/2022, 5:06 AMexecuteAsList()
does, but if it returns a Sequence
then its operators are not inlinedZoltan Demant
09/04/2022, 5:10 AMfun executeAsList(): List<RowType> {
val result = mutableListOf<RowType>()
execute().use {
while (it.next()) result.add(mapper(it))
}
return result
}
Zoltan Demant
09/04/2022, 5:14 AMephemient
09/04/2022, 5:18 AMZoltan Demant
09/04/2022, 5:23 AMephemient
09/04/2022, 5:25 AMZoltan Demant
09/04/2022, 5:30 AM