[Feature]: Provide ability to pass CancellationToken into Async methods
See original GitHub issueIs 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);
Issue Analytics
- State:
- Created 2 years ago
- Reactions:11
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Associate a CancellationToken with an async method's Task
Run , you'll get a canceled task that raises TaskCanceledException when await ed, but if you cancel a token passed to Task.Run after...
Read more >Recommended patterns for CancellationToken
Know when you've passed the point of no cancellation. · Propagate your CancellationToken to all the methods you call that accept one, except ......
Read more >Patterns & Practices for efficiently handling C# async/await ...
The simplest pattern for cancellation processing is to provide a CancellationToken at the end of the argument and propagate it to the inner ......
Read more >Cancelling await calls in .NET 6 with Task.WaitAsync()
In this post I discuss the new Task.WaitAsync() APIs introduced in .NET 6 and how you can use them to cancel an await...
Read more >Cancellation with Async F#, C# and the Reactive Extensions
The problem here is pretty simple: the cancellation token only cancels the task created by Task.Run(). This can be problematic, particularly if ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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 theawait 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.
Hi! Thanks for the suggestion. This is definitely something to consider. For now, I’ve marked it as collecting feedback, and we’ll go from there.