Davide Giuseppe Farella
01/15/2020, 8:40 PMDico
01/15/2020, 8:45 PMisActive is from kotlinx.coroutines, it is because there is no Job element in your coroutine context.Dico
01/15/2020, 8:46 PMDavide Giuseppe Farella
01/15/2020, 8:47 PMthere is no? Putting a breakpoint outside of theelement in your coroutine contextJob
object , below isEmpty it is trueDico
01/15/2020, 8:48 PMDavide Giuseppe Farella
01/15/2020, 9:01 PMDavide Giuseppe Farella
01/15/2020, 9:01 PMDominaezzz
01/15/2020, 9:17 PMcoroutineScope is finished when iterator returns, so it prints false.streetsofboston
01/15/2020, 9:18 PMcoroutineScope from the AnIterableClass#iterator() function and add it to the hasNext() function instead, you get what you expectDavide Giuseppe Farella
01/15/2020, 9:33 PMDominaezzz
01/15/2020, 9:35 PMcoroutineScope for the iterator at all, you can just do coroutineContext.isActive I think.Dominaezzz
01/15/2020, 9:35 PMFlow ....streetsofboston
01/15/2020, 9:37 PMclass AnIterableClass {
operator fun iterator() =
object : SuspendIterable {
override suspend fun hasNext(): Boolean = coroutineScope {
println("2 $isActive")
false
}
}
}
The couroutineScope closure is moved to the hasNext. (and suspend has been removed from iterator).