khairil.ushan
09/02/2018, 5:04 PMsearch
function after user finish typing (by being idle for >=400ms). is this the correct way to do this with coroutines?
fun onKeywordChanged(keyword: String) {
keywordJob.cancel()
keywordJob = launch {
delay(400)
if (!isActive) return@launch
search(keyword)
}
}
gildor
09/03/2018, 1:48 AMacando86
09/03/2018, 8:40 AMgildor
09/03/2018, 8:42 AMkhairil.ushan
09/03/2018, 12:36 PMDaniel Tam
09/04/2018, 4:23 AMif (!isActive)
isn't necessary because delay() will resume with an exception if the coroutine is cancelled anywaywithTimeout
or the onTimeout
clause with select to do something a bit nicer. E.g. withTimeout(400) { keywordChannel.receive() }