package com.example.base.extensions

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch


/**
 * @param maxCount 时长
 * @param delay 间隔
 * @param block 回调
 */
fun ViewModel.countDown(
    maxCount: Int,
    delay: Long = 1000,
    block: (Int) -> Unit
): Job {
    return viewModelScope.launch {
        repeat(maxCount) {
            block.invoke(maxCount - (it + 1))
            delay(delay)
        }
    }
}


