-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Description
I'm trying to convert an Android CountDownTimer into emitting values via callbackFlow but it throws ClosedSendChannelException: Channel was closed when collecting the items. I can't really find a valid reason why this happens.
@ExperimentalCoroutinesApi
class TimerFlow private constructor(millisInFuture: Long, countDownInterval: Long) {
private val tick: Flow<Long> = callbackFlow {
object : CountDownTimer(millisInFuture, countDownInterval) {
override fun onFinish() {
offer(0L)
}
override fun onTick(millisUntilFinished: Long) {
Log.i("TimerFlow","$millisUntilFinished")
offer(millisUntilFinished)
}
}.start()
}
companion object {
/**
* Create a [Flow] that will be a countdown until a specified time in the future.
*
* @param millisInFuture The milliseconds in the future that this will countdown to.
* @param countDownInterval The minimum amount of time between emissions.
*/
@JvmStatic
fun create(millisInFuture: Long, countDownInterval: Long) =
TimerFlow(millisInFuture, countDownInterval).tick
}
}Is this a bug or am I missing something? I'm new to Coroutines.