https://kotlinlang.org logo
#coroutines
Title
# coroutines
t

tseisel

10/04/2019, 2:59 PM
For testing purposes, I need a flow that never completes (similar to
Flowable.never()
) Is something like this correct ?
Copy code
object NeverFlow : Flow<Nothing> {
    override suspend fun collect(collector: FlowCollector<Nothing>) {
        delay(Long.MAX_VALUE)
    }
}
s

streetsofboston

10/04/2019, 3:01 PM
Copy code
val flow: Flow<Nothing> = flow {
        suspendCancellableCoroutine { /* do nothing */ }
    }
👍 1
Basically, replace the
delay(Long.MAX_VALUE)
call with an empty
suspendCancellableCoroutine
call
e

elizarov

10/05/2019, 4:16 PM
Actually, that is exactly what delay would do if you call it with
Long.MAX_VALUE
— it assumes you suspend forever.
s

streetsofboston

10/05/2019, 5:26 PM
Had some issues with unit-testing code that uses
delay(Long.MAX_VALUE)
, due to Long.MAX_VALUE rolling over to a negative value of you add just 1 millisecond. Maybe that has been fixed in the latest coroutines-test libraries. If not, calling
delay(Long.MAX_VALUE - 1)
may still have that roll-over issue...
2 Views