Questions tagged [cancellation]
Cancellation is paradigm that allows cooperatively canceling a running operation before it finishes.
cancellation
740
questions
196
votes
8
answers
131k
views
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 ...
190
votes
4
answers
225k
views
How to cancel a Task in await?
I'm playing with these Windows 8 WinRT tasks, and I'm trying to cancel a task using the method below, and it works to some point. The CancelNotification method DOES get called, which makes you think ...
181
votes
13
answers
147k
views
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 ...
169
votes
4
answers
316k
views
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 ...
158
votes
17
answers
180k
views
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 ...
82
votes
10
answers
55k
views
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 ...
80
votes
5
answers
32k
views
How to "sleep" until timeout or cancellation is requested
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 Framework 4.0+...
63
votes
6
answers
71k
views
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 ...
41
votes
4
answers
20k
views
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, ...
40
votes
3
answers
25k
views
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 ...
32
votes
4
answers
18k
views
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('...
32
votes
3
answers
14k
views
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 ...
31
votes
2
answers
19k
views
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 ...
25
votes
3
answers
11k
views
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 ...
25
votes
4
answers
28k
views
Thread.Abort vs Thread.Interrupt
If I need to cancel some operation on a thread, when should I use Thread.Abort vs Thread.Interrupt. I read the documentation on it but not sure which scenario should I use a particular call between ...
24
votes
2
answers
6k
views
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 ...
24
votes
3
answers
33k
views
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 ...
23
votes
2
answers
9k
views
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 ...
21
votes
3
answers
14k
views
How to force an IAsyncEnumerable to respect a CancellationToken
I have an async iterator method that produces an IAsyncEnumerable<int> (a stream of numbers), one number every 200 msec. The caller of this method consumes the stream, but wants to stop the ...
21
votes
6
answers
19k
views
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.
...
21
votes
2
answers
12k
views
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(...
20
votes
1
answer
15k
views
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 ...
19
votes
1
answer
16k
views
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/...
18
votes
2
answers
5k
views
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 ...
18
votes
1
answer
9k
views
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 ...
17
votes
4
answers
35k
views
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:
<Window
...
x:Class="MyApp.MyView"
...
/>
<Button Content="...
16
votes
7
answers
45k
views
How to integrate AbortController with Axios and React?
The Abortcontroller signal is not working for me with Axios in React.
I wanted to replace CancelToken (as it's deprecated) with the AbortController, but it is not working, respectively the requests ...
16
votes
4
answers
13k
views
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 ...
16
votes
4
answers
16k
views
Stopping a task without a CancellationToken
I am using an external library that has async methods, but not CancellationToken overloads.
Now currently I am using an extension method from another StackOverflow question to add a CancellationToken:...
16
votes
2
answers
5k
views
Stop Parallel.ForEachAsync
In C#, I am interested in stopping a Parallel.ForEachAsync loop (considering the differences between Stop and Break); for Parallel.ForEach I can do the following:
Parallel.ForEach(items, (item, state) ...
16
votes
4
answers
14k
views
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....
16
votes
1
answer
5k
views
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<IActionResult> Get()
{
...
15
votes
1
answer
4k
views
why does pthread_exit throw something caught by ellipsis?
if the function called by pthread_create has the following structure
try{
...code....
pthread_detach(pthread_self());
pthread_exit(NULL);
}catch(...){
std::cout<<"I am here"<<std::...
15
votes
1
answer
5k
views
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 ‘...
15
votes
3
answers
4k
views
how can I cancel an Ajax request? [duplicate]
In phonegap how to cancel an ajax request in program, I would like to set cancel button for control the request when it's too slow
$.ajax({
type: "GET",
url: url,
success: function(m) {
...
15
votes
2
answers
10k
views
Checking if a Java Timer is cancelled
Why is there no isCancelled method for a java.util.Timer object?
I would like to schedule a task if the Timer has not been cancelled, and run it directly (on the same thread) if it has been cancelled....
15
votes
2
answers
6k
views
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 = ...
15
votes
2
answers
2k
views
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:
...
14
votes
1
answer
9k
views
Getting the saved instruction pointer address from a signal handler
My question is somewhat different from others that have asked about fault addresses. I'm trying to implement a horrible hack to determine, from a signal handler, whether the signal interrupted a ...
13
votes
1
answer
3k
views
F# How Async<'T> cancellation works?
I was pretty comfortable with how async cancellations where done in C# with the TPL, but I am a little bit confused in F#. Apparently by calling Async.CancelDefaultToken() is enough to cancel outgoing ...
13
votes
2
answers
21k
views
Active Noise Cancellation through default iPhone headphone
We want to create an App that will implement the Active Noise Cancellation using the default iPhone headphone. That is, to receive the external audio using the iPhone headphone Mic and make a phase ...
12
votes
4
answers
7k
views
Cancellation with Future and Promise in Scala
This is a followup to my previous question.
Suppose I have a task, which executes an interruptible blocking call. I would like to run it as a Future and cancel it with failure method of Promise.
I ...
12
votes
2
answers
12k
views
How can I stop async Process by CancellationToken?
I found beneath code for execute some process without freezing UI. This code is executed when 'Start Work' button is pressed. And I think users would stop this work by 'Stop' button. So I found this ...
11
votes
1
answer
6k
views
Proper way to use LINQ with CancellationToken
I am trying to write a LINQ query that would support cancellation using the CancellationToken mechanism that is provided in the .NET framework. However, it's unclear what the proper way to combine ...
11
votes
2
answers
3k
views
How to stop a java code from running using a stop button
I have a button that calls a method from the backing Bean. This method allows to extract data from parsing html code. While the method is running i have a dialog showing a progress bar and a command ...
11
votes
1
answer
7k
views
Capturing CancelKeyPress to stop an async console app at a safe point
I'm working on a small utility console app, built in C# 7.1 (which has async Main support).
The app takes one of several input commands and then starts a long-running process which iterates through ...
11
votes
1
answer
500
views
Is there any movement towards specifying interaction of C++ exceptions and pthread cancellation?
The GNU C library uses DWARF2 unwinding for pthread cancellation these days, so that both C++ exceptions and pthread cancellation cleanup handlers get called through a common call frame unwinding ...
11
votes
2
answers
2k
views
std::atomic_bool for cancellation flag: is std::memory_order_relaxed the correct memory order?
I have a thread that reads from a socket and generates data. After every operation, the thread checks a std::atomic_bool flag to see if it must exit early.
In order to cancel the operation, I set ...
10
votes
5
answers
11k
views
How to cancel an observable sequence
I have a very simple IObservable<int> that acts as a pulse generator every 500ms:
var pulses = Observable.GenerateWithTime(0, i => true, i => i + 1, i => i,
...
10
votes
3
answers
3k
views
Task.Wait unexpected behavior in case of OperationCanceledException
Consider the following piece of code:
CancellationTokenSource cts0 = new CancellationTokenSource(), cts1 = new CancellationTokenSource();
try
{
var task = Task.Run(() => { throw new ...