suspend fun getBooks(page: Int, limit: Int): List fun loadBooks(): ReceiveChannel = produce(CommonPool) { var page = 0 while (true) { val books = getBooks(page++, LIMIT) if (books.isEmpty()) break books.forEach { send(it) } if (books.size < LIMIT) break } } 簡単に書けるメソッドもあるよ!