gotoOla
05/26/2020, 9:18 AMprivate suspend fun processAndSend() {
documentService.getDocuments(reference) // returns a Sequence<Documents>
.chunked(10)
.map { chunkedDocuments ->
val processedDocuments = httpClient.processDocuments(chunkedDocuments) // compile error, suspending call
queueSender.send(processedDocuments) // compile error, suspending call
}
}
// compile error = Suspension functions can be called only within coroutine bodyaraqnid
05/26/2020, 9:21 AM.asFlow() before map to open up calling arbitrary suspend functionsgotoOla
05/26/2020, 9:30 AMyield?gotoOla
05/26/2020, 9:33 AMsuspend fun getDocuments()
that makes sense then.. I guess I could rewrite the sequence to a flow if I want a non-blocking behavior then?araqnid
05/26/2020, 9:33 AMsequence{} is only allowed to suspend by calling yield (ultimately, maybe via yieldAll or some other extension of SequenceScope).
This is totally independent of things like coroutineScope from the kotlinx.coroutines librarygotoOla
05/26/2020, 9:33 AMaraqnid
05/26/2020, 9:58 AM