-
Notifications
You must be signed in to change notification settings - Fork 9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature]: ability to cancel "waitFor" promises #9709
Comments
Have you tried using |
Thanks, I hadn't considered that. I still think this might be a useful feature since you could be waiting on different kind of things, e.g. I could try implementing using an AbortController strategy. So it would be used like this? // calls abort() once one of the promises fulfills
async function smartAny(abort, promises) {
const result = await Promise.any(promises);
abort();
return result;
}
const { signal, abort } = new AbortController();
await smartAny(abort, [page.waitForSelector("#login-success", { signal }), page.waitForNavigation({ signal })]) |
Actually, instead of calling const abortController = new AbortController();
await Promise.any([
page.waitForSelector("#login-success", { abortController }),
page.waitForNavigation({ abortController })
]) |
Is AbortController available in Node14+? |
Nope, but there are a few JavaScript implementations available, e.g. https://github.com/southpolesteve/node-abort-controller |
Can this be added to other waitFor functions, like |
Feature description
I'm using
page.waitForSelector
in this way to determine which page I landed on:The problem with this is that if one of the promises completes early, the others will keep on retrying until their timeout expires (I assume waitFor is internally implemented using setTimeout/setInterval). That can create a lot of unnecessary computation especially for a long array of
page.waitForSelector
.It would be good if there was a way to cancel the promise it returns. For example, it could enable this:
I would be able to work on a pull request if there is interest.
The text was updated successfully, but these errors were encountered: