Run button handler asynchronously


Hi, I have an alert controller which has some checkboxes, but the handler takes too long to finish.

What I want is to click the checkbox and that the handler is handled asynchronously, meaning that I don’t have to wait for it to finish. Adding async didn’t work.

My code for this is:

this.listaVideosAux.forEach(lista => {
        type: 'checkbox',
        label: lista.nombre,
        value: lista.nombre,
        checked: true,
        handler: async checkBox => {
          if (checkBox.checked) {
          } else {
            this.categoriasFiltro = this.categoriasFiltro.filter(categoria => categoria != checkBox.value)



What I want is that once you’ve pressed a checkbox it does the “pressed” effect. I don’t mind if it takes some time to do what the handler wants to do. But as it is now, it’ll do that effect once the handler is done which looks horrible to me.


Assuming filtrar is the long-running task, that’s all you really need to make asynchronous. Once it is, it will return immediately, and your handler will be considered “done” as soon as filtrar has begun.


Even if I used async without await, it was still waiting. What I’ve do is to remove the async modifier and return a promise. Then I’ve put what’s inside filtrar into a settimeout and out of that settimeout and at the end the method I resolve the promise.