I am trying to implement the debounce pattern in C...
# compose
d
I am trying to implement the debounce pattern in Compose when typing inside a TextField, to limit the number of network requests. This code seems to work very well. However, in this case a new coroutine is launched every time the user presses a key. I wonder if it's an overkill, and it could be implemented differently, or it's efficient enough.
Copy code
BasicTextField( value = text,
    onValueChange = {
        text = it
        updateListFilter(value)
    }
)
....
val debounceMillis: Long = 300
var debounceJob: Job? = null

fun UpdateListFilter(filter) {
    debounceJob?.cancel()
    debounceJob = coroutineScope.launch {
        delay(debounceMillis)
        makeNetworkRequest(filter)
    }
}