Well this works, feels bad though: ```private val ...
# coroutines
k
Well this works, feels bad though:
Copy code
private val loop = iterator {
    for (i in 0 until 10) {
        println(i)
        yield(Unit)
    }
}

fun doIteration() {
    loop.next()
}
n
This is part of the standard library, not coroutines. Try asking in #general. Also please use threads on Slack so questions don't get buried!
k
I'm specifically asking about how to do this myself with coroutines.
n
Do you need it to be suspending? And if so where is the point of suspension? I see your yield call
k
The point of suspending is that the loop literally needs to suspend for
doIteration
to return.
n
No, I understand that, I mean where do you want it to suspend. Anyway, maybe this will help: https://github.com/Kotlin/kotlinx.coroutines/blob/master/docs/channels.md#building-channel-producers I believe you can simply consume one at a time, which seems to meet your needs, although it would take some refactoring.
d
In your specific example, you might be able to use a dispatcher that stores the continuation for the next call.
k
@nwh That seems to be what I was looking for, thanks!
👍🏻 1
e
The design document provides explanations and examples on how to write things like that https://github.com/Kotlin/KEEP/blob/master/proposals/coroutines.md