【发布时间】:2021-06-27 23:50:43
【问题描述】:
有什么办法可以跳过 kotlin 协程中的延迟。
setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String): Boolean {
// todo: skip the delay
return true
}
private var textChangeCountDown: Job? = null
override fun onQueryTextChange(text: String): Boolean {
textChangeCountDown?.cancel()
textChangeCountDown = lifecycleScope.launch {
// here is the dalay that need to be skipped when query text submit
delay(800)
// text changed to $text
}
return true
}
})
当用户点击提交时,我想跳过延迟,就像这样:
val mDelay = delay(800)
// mDelay.continue()
// mDelay.cancel()
有这样的功能吗?
【问题讨论】:
标签: android kotlin kotlin-coroutines