Questions tagged [cancellation]

Cancellation is paradigm that allows cooperatively canceling a running operation before it finishes.

Cancellation is paradigm that allows cooperatively canceling a running operation before it finishes.

In , cancellation is achieved using for signaling cancellation and a CancellationToken is used by the operation to check whether cancellation was requested.

712 questions
22
votes
2 answers

Any way to differentiate Cancel and Timeout

I have some code that is validating some data by making calls to a number of other services. I start all of the calls in parallel and then wait until at least one of them finishes. If any of the requests fail, I don't care about the result of the…
21
votes
6 answers

SwingWorker: when exactly is called done method?

Javadoc of the done() method of SwingWorker: Executed on the Event Dispatch Thread after the doInBackground method is finished. I've clues that it is not true in the case of canceled worker. Done is called in each case (normal termination or…
AgostinoX
  • 7,477
  • 20
  • 77
  • 137
20
votes
1 answer

How to copy Context object without deriving

I want to make a copy of a context object - a request context to be exact, and make use of it later on in a separate go routine. Problem is if I derive the request context using context.WithCancel(reqCtx) once the HTTP handler for this request is…
Mr. Nicky
  • 1,519
  • 3
  • 18
  • 34
20
votes
1 answer

How to cancel http request properly in Node.js?

I need to implement a cancel-able client-side HTTP request in Node.js, without using external libraries. I'm giving a Promise object - cancellationPromise - which gets rejected when the cancellation is externally requested. This is how I know I may…
avo
  • 10,101
  • 13
  • 53
  • 81
19
votes
1 answer

Parallel.Foreach exceptions and cancel

I have tried to find out how exceptions and cancel work for Parallel.Foreach. All examples seems to deal with Tasks. What happens on an exception in Parallel.Foreach? Do I wrap the entire loop in try/catch (AggregateException)? Will all other tasks…
adrianm
  • 14,468
  • 5
  • 55
  • 102
18
votes
1 answer

Aborting a long running task in TPL

Our application uses the TPL to serialize (potentially) long running units of work. The creation of work (tasks) is user-driven and may be cancelled at any time. In order to have a responsive user interface, if the current piece of work is no…
Andrew Anderson
  • 3,409
  • 22
  • 25
17
votes
3 answers

How to force an IAsyncEnumerable to respect a CancellationToken

I have an async iterator method that produces an IAsyncEnumerable (a stream of numbers), one number every 200 msec. The caller of this method consumes the stream, but wants to stop the enumeration after 1000 msec. So a CancellationTokenSource…
Theodor Zoulias
  • 34,835
  • 7
  • 69
  • 104
17
votes
2 answers

Whats the benefit of passing a CancellationToken as a parameter to Task.Run?

Obviously I realize it enables me to cancel the task, but this code achieves the same effect without having to pass the token into Task.Run What is the practical difference? Thanks. Dim cts As New CancellationTokenSource Dim ct As CancellationToken…
JohnWick
  • 4,929
  • 9
  • 37
  • 74
17
votes
4 answers

How to cancel window closing in MVVM WPF application

How can I cancel exiting from particular form after Cancel button (or X at the top right corner, or Esc) was clicked? WPF:
16
votes
4 answers

Cancel a promise when a component is unmounted in ReactJS

I've a component named "Item" which creates and calls a promise when it has been mounted. class Item extends React.Component{ constructor(props){ super(props) this.onClick = this.onClick.bind(this) this.prom = new…
amone
  • 3,712
  • 10
  • 36
  • 53
16
votes
4 answers

How to retract a message in RabbitMQ?

I've got something like a job queue over RabbitMQ and, upon a request to cancel a job, I'd like to retract the tasks that have not yet started processing (their messages have not been ack'd), which corresponds to retracting these messages from the…
jkff
  • 17,623
  • 5
  • 53
  • 85
16
votes
1 answer

Status of cancellable promises

The oldest issue on https://github.com/promises-aplus/cancellation-spec is (at the time of writing) 9 months old. I really can’t found a reliable source of information about cancellation features on ‘standard’ promises. By now looks like the feature…
Pier Paolo Ramon
  • 2,780
  • 23
  • 26
15
votes
2 answers

Do asynchronous context managers need to protect their cleanup code from cancellation?

The problem (I think) The contextlib.asynccontextmanager documentation gives this example: @asynccontextmanager async def get_connection(): conn = await acquire_db_connection() try: yield conn finally: await…
Maxpm
  • 24,113
  • 33
  • 111
  • 170
15
votes
1 answer

HttpRequest not aborted (cancelled) on browser abort in ASP.NET Core MVC

I wrote the following MVC Controller to test cancellation functionality: class MyController : Controller { [HttpGet("api/CancelTest")] async Task Get() { await Task.Delay(1000); CancellationToken token =…
15
votes
2 answers

Retrofit + Okhttp cancel operation not working

I am using retrofit in my application like this final OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.interceptors().add(new YourInterceptor()); final OkClient okClient = new OkClient(okHttpClient); Builder…
SHASHIDHAR MANCHUKONDA
  • 3,302
  • 2
  • 19
  • 40
1
2
3
47 48