一次性计时器
先实现一个一次性的计时器,如下:
open class OnceCommonTimer(private val timeOutCallback: () -> Unit) {
fun start(interval: Long) {
if (stoped == false) {
stop()
}
stoped = false
job = CoroutineScope(Dispatchers.Default).launch {
delay(interval)
CoroutineScope(Dispatchers.Main).launch {
timeOutCallback()
}
stop()
}
job?.start()
}
fun stop() {
stoped = true
job?

1325

被折叠的 条评论
为什么被折叠?



