Does canceling a $timeout in the following 'then' function work?

50 Views Asked by At

I do this kind of all the time and I'm not too sure it works. If it does, How can I check? If it doesn't whats a better method of canceling a timeout after it's completed?

var delay = $timeout(function() {
      for (i = 0; i < allHighlightedEls.length; i += 1) {
       //... some transformations
      }
    }, 1000)
      .then(function() {
        $timeout.cancel(delay);
      });
1

There are 1 best solutions below

1
Quentin On BEST ANSWER

After it is completed, it is completed. There is nothing left to cancel.

Calling cancel on it does nothing.