<cancelling a suspend function in kotlin if the sa...
# stackoverflow
u
cancelling a suspend function in kotlin if the same function is called again I want to cancel the function i created which simply increments a counter value. For example, if the specific function is triggered by click, I only want to display the log for the last uninterrupted click within 2 seconds. Basically, i want the function to cancel itself if called again if its ongoing (delay is ongoing). Is there such thing in kotlin? val counter = mutableStateOf(0) suspend fun addCounter(){ counter.value++ delay(2000) Log.e("click cat","click $counter") }`