As we learned earlier, waitFor will repeatedly search our screen for a given template image.
This great flexibility does not come for free, so we might not want to wait for the timeout to fire before we can cancel the ongoing search. nut.js follows the same approach to cancellation as the browser fetch API, using an AbortController.
Before we can actually look at a sample, we will have to install an additional package to our project:
Now, let's take a look at a (rather artificial) example:
waitFor has a timeout of 5000 milliseconds configured, retrying after 1000 milliseconds, but after 2000 milliseconds, we call
abort() on our AbortController, which will cancel the ongoing search:
waitForis cancelable using an AbortController.