Skip to content
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]: Provide ability to pass CancellationToken into Async methods #1652

Closed
FutureTD opened this issue Aug 3, 2021 · 5 comments
Closed

Comments

@FutureTD
Copy link

FutureTD commented Aug 3, 2021

Is there a way to use cancellation tokens to cancel async operations?

It would be helpful to have most of the async methods able to be cancelled. Especially methods like

await page.GotoAsync("https://github.com/");

which would then be:

await page.GotoAsync("https://github.com/", cancellationToken);

@FutureTD FutureTD changed the title Cancelling async operations [Question]: Cancelling async operations Aug 3, 2021
@avodovnik avodovnik changed the title [Question]: Cancelling async operations [Feature request]: Cancelling async operations Aug 4, 2021
@avodovnik avodovnik changed the title [Feature request]: Cancelling async operations [Feature request]: Provide ability to pass CancellationToken into Async methods Aug 4, 2021
@avodovnik

This comment was marked as outdated.

@mxschmitt mxschmitt changed the title [Feature request]: Provide ability to pass CancellationToken into Async methods [Feature]: Provide ability to pass CancellationToken into Async methods Aug 6, 2021
@fr4gles
Copy link

fr4gles commented Sep 8, 2021

Yea, it would be nice.
In our project on some cases we are using "dirty task cancellation" similar to this https://devblogs.microsoft.com/pfxteam/how-do-i-cancel-non-cancelable-async-operations/

@icalvo
Copy link

icalvo commented Apr 25, 2022

I think that for most cases it would be more than enough to pass the CancellationToken to CreateAsync() and then check the cancellation in all operations.

@mxschmitt
Copy link
Member

Closing it, since there are no plans to support it. Browser interactions like clicks, fills are all not cancelable, so even if we would provide it, it would be a kinda fake cancel, and a certain action would still run in the background.

@schrufygroovy
Copy link

@mxschmitt this is true from a browser user perspective, but I think it's really not about cancelling any actions/commands but more about cancelling potential waiting process for the callbacks of the commands.

As far as I can see all commands are sent via SendMessageToServerAsync() - and for each command the callback is being awaited. Why should it not be reasonable to cancel this instead of waiting for callback to be fulfilled? For example when I want to cancel the execution (e.g: some test run, or some executable), why would I still need to wait until the await page.GotoAsync("https://github.com/") command is having some callback. I just want the execution to be stopped gracefully as fast as possible and no "hanging" execution.

I would really appreciate, if you would reconsider your decision or give us some alternative way to gracefully cancel pending commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants