David Glasser
02/29/2020, 2:43 AMfun listFiles(bucket: String, prefix: String): Flow<Blob> = flow {
var page = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
gcs.list(bucket, BlobListOption.prefix(prefix))
}
while (true) {
emit(page)
if (!page.hasNextPage()) {
break
}
page = withContext(<http://Dispatchers.IO|Dispatchers.IO>) { page.nextPage }
}
}.flatMapConcat { page ->
page.values.asFlow()
}
but I don't know if that is rightlouiscad
02/29/2020, 6:27 AMflowOn
David Glasser
02/29/2020, 7:15 AMflow {
var page = gcs.list(bucket, BlobListOption.prefix(prefix))
while (true) {
emit(page)
if (!page.hasNextPage()) {
break
}
page = page.nextPage
}
}
.flowOn(<http://Dispatchers.IO|Dispatchers.IO>)
.flatMapConcat { page -> page.values.asFlow() }
louiscad
02/29/2020, 8:20 AMflowOn
(and Flow
) in general to understand what you do and get confidence.