Slide 21
Slide 21 text
suspend fun getBooks(page: Int, limit: Int): List
fun loadBooks(): ReceiveChannel { // 受信 (receive) 専用 Channel
val channel = Channel()
launch(CommonPool) {
var page = 0
while (true) {
val books = getBooks(page++, LIMIT)
if (books.isEmpty()) break
books.forEach { channel.send(it) }
if (books.size < LIMIT) break
}
channel.close()
}
return channel
}