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
196
votes
8 answers

How to cancel an $http request in AngularJS?

Given a Ajax request in AngularJS $http.get("/backend/").success(callback); what is the most effective way to cancel that request if another request is launched (same backend, different parameters for instance).
mpm
  • 20,148
  • 7
  • 50
  • 55
169
votes
13 answers

Promise - is it possible to force cancel a promise

I use ES6 Promises to manage all of my network data retrieval and there are some situations where I need to force cancel them. Basically the scenario is such that I have a type-ahead search on the UI where the request is delegated to the backend has…
Moonwalker
  • 3,462
  • 4
  • 25
  • 31
166
votes
4 answers

How to use the CancellationToken without throwing/catching an exception?

Compared to the preceding code for class RulyCanceler, I wanted to run code using CancellationTokenSource. How do I use it as mentioned in Cancellation Tokens, i.e. without throwing/catching an exception? Can I use the IsCancellationRequested…
Fulproof
  • 4,466
  • 6
  • 30
  • 50
156
votes
17 answers

Cancel a vanilla ECMAScript 6 Promise chain

Is there a method for clearing the .thens of a JavaScript Promise instance? I've written a JavaScript test framework on top of QUnit. The framework runs tests synchronously by running each one in a Promise. (Sorry for the length of this code…
dx_over_dt
  • 13,240
  • 17
  • 54
  • 102
81
votes
10 answers

Is there a way to short circuit async/await flow?

All four functions are called below in update return promises. async function update() { var urls = await getCdnUrls(); var metadata = await fetchMetaData(urls); var content = await fetchContent(metadata); await render(content); …
sbr
  • 4,735
  • 5
  • 43
  • 49
76
votes
5 answers

How to "sleep" until timeout or cancellation is requested in .NET 4.0

What's the best way to sleep a certain amount of time, but be able to be interrupted by a IsCancellationRequested from a CancellationToken? I'm looking for a solution which works in .NET 4.0. I'd like to write void MyFunc (CancellationToken ct) { …
Onur
  • 5,017
  • 5
  • 38
  • 54
57
votes
5 answers

What is the Correct HTTP Status Code for a Cancelled Request

When a TCP connection gets cancelled by the client while making a HTTP request, I'd like to stop doing any work on the server and return an empty response. What HTTP status code should such a response return?
Muhammad Rehan Saeed
  • 35,627
  • 39
  • 202
  • 311
41
votes
4 answers

Can jQuery deferreds be cancelled?

I have a situation where I want to cancel a deferred. The deferred is associated with an ajax call. Why I am using deferreds I don't use the normal xhr objects returned by $.ajax. I'm using jsonp, which means I can't use HTTP status codes for error…
user879121
40
votes
3 answers

How to stop a DispatchWorkItem in GCD?

I am currently playing around with Grand Central Dispatch and discovered a class called DispatchWorkItem. The documentation seems a little incomplete so I am not sure about using it the right way. I created the following snippet and expected…
29
votes
2 answers

What exactly is a cancellation point?

I am trying to get my head around what exactly a cancellation point is in c++. I have read: man page and What are pthread cancellation points used for But I am still a little confused on certain points. For example, I am using the file write()…
code_fodder
  • 15,263
  • 17
  • 90
  • 167
29
votes
4 answers

How to cancel timeout inside of Javascript Promise?

I'm toying with promises in JavaScript and tried to promisify setTimeout function: function timeout(ms) { return new Promise(function(resolve, reject) { setTimeout(function() { resolve('timeout done'); }, ms); }); } var…
spirytus
  • 10,726
  • 14
  • 61
  • 75
28
votes
3 answers

How to cancel all remaining tasks in gather if one fails?

In case one task of gather raises an exception, the others are still allowed to continue. Well, that's not exactly what I need. I want to distinguish between errors that are fatal and need to cancel all remaining tasks, and errors that are not and…
user4385532
24
votes
2 answers

How can I wait on tasks without throwing TaskCanceledExceptions?

I have a method that creates some Tasks, and then waits on them with WaitAll before returning. The problem is, if those tasks got canceled, then WaitAll throws an AggregateException containing lots of TaskCanceledExceptions. That means that WaitAll…
Joe White
  • 94,807
  • 60
  • 220
  • 330
23
votes
3 answers

Sidekiq stop one single, running job

So I need to stop a running Job in Sidekiq (3.1.2) programmatically, not a scheduled one. I did read the API documentation but didn't really find anything about cancelling running jobs. Is this possible with sidekiq? When this is not directly…
Figedi
  • 383
  • 1
  • 2
  • 11
22
votes
3 answers

Context without cancel propagation

How can I create a copy (a clone if you will) of a Go context that contains all of the values stored in the original, but does not get canceled when the original does? It does seem like a valid use case to me. Say I have an http request and its…
Nestor Sokil
  • 2,162
  • 12
  • 28
1
2 3
47 48