750 questions
0
votes
1
answer
105
views
How to terminate an asynchronous function at any point?
I'm looking to cancel an asynchronous function based on a signal that can be controlled by anything, similar to how a fetch can be aborted through the use of an AbortController - effectively ...
0
votes
3
answers
145
views
Are there any real difference between GlobalScope and CoroutineScope?
I'm trying to understand the difference between the 2.
If a CoroutineScope is not tied to any lifecycle-aware component, then I think they behave the same:
If Im not passing any context to ...
1
vote
0
answers
92
views
How to cancel a gRPC client streaming call cleanly without triggering RpcException, ObjectDisposedException, or InvalidOperationException?
I'm working on a gRPC client that continuously streams data (such as images) from a server. I use a CancellationToken to stop the stream when needed. While cancellation works, I consistently see ...
1
vote
0
answers
98
views
Cleanup after waiting for first asyncio task to complete: Is it safe to swallow CancelledError when raised by task.get_exception()?
I have an asyncio function that spawns multiple tasks, any of which can return a result, in which case we want to shut down all the others.
Right now, it does so in a matter something like the ...
0
votes
1
answer
180
views
What is the significance of the cancellation token in the call to Task.Run? [duplicate]
In my application I have a synchronous method that I am calling asynchronously by invoking Task.Run. I've noticed that the Task.Run call takes a cancellation token. However, in my tests I noticed that ...
3
votes
2
answers
202
views
How to detect stdin input in a cancel-safe way in Rust async?
Problem
I'm working with asynchronous code in Rust and trying to handle user input from stdin in a cancel-safe manner. My goal is to be able to detect when a user presses a key (or hits enter) to ...
1
vote
1
answer
76
views
Design pattern with multiple cancellable tasks and unhandled exception handling [duplicate]
I want a C# console app that
Runs multiple tasks
Cancellable by Control C
Unhandled exceptions in one task, cleanly cancel the other tasks.
The below code deals with the cancellation correctly, but ...
3
votes
2
answers
127
views
Is there an event I can subscribe to from a job that is raised when Stop-Job is invoked on that job?
The following code demonstrates that a long-running (but, in principle, cancellable) .Net method called from a job runs to completion even when the job is stopped:
$stopwatch = [System.Diagnostics....
0
votes
0
answers
107
views
Handling TaskCanceledException by IExceptionHandler
I'm trying to implement a generic timeout for my requests in C#. I'm aware of the request timeout middleware, but it can't be instructed (as the middleware is handling the exception) to pass the ...
0
votes
1
answer
87
views
.NET 8 socket ReadAsync: why the last reply is reported exactly at the time of cancellation?
I need to wait for replies for UDP broadcast with timeout, so I try ReadAsync with cancellation token and Threading.Timer to signal cancellation. There are two other computers, which reply to the ...
1
vote
1
answer
105
views
Merging two IAsyncEnumerable instances with cancellation support (NotSupportedException)
I'm having trouble implementing the following properly:
I have two IAsyncEnumerable instances (of the same type), one is the "primary" source, the purpose of the other is so the user can &...
0
votes
1
answer
613
views
How to prevent <dialog> to close with Esc key [duplicate]
The HTML element <dialog> is intended to always be closed when you press Esc key according to documentation. The problem with that is that you might want it not to close immediately, i.e. if you ...
2
votes
1
answer
125
views
Unable to cancel a Task returned by TaskCompletionSource by injecting a timeout in C#
I have the following method that waits for an event to happen to set the results by a TaskCompletionSource.
private async Task<string?> RequestDataAsync(string? remoteEntity, CancellationToken ...
-1
votes
1
answer
77
views
Cancelling an upload request (using xhr, axios or superagent) blocks other following requests
My need is to upload a large file (several megabytes or even at least one gigabyte) and allow users to cancel the current upload request.
Unfortunately, when i cancel the request via AbortController, ...
0
votes
0
answers
77
views
How do I cancel a long running task from a DELETE endpoint in ASP.NET Core?
I have an API to generate a long running task and a different API to fetch the result (can also be called to get a partial result).
An example:
[HttpGet]
public IActionResult LongRunning()
{
var ...
1
vote
1
answer
146
views
Disposing an IAsyncEnumerator does not cancel the underlying IAsyncEnumerable's cancellation token
It appears that disposing a generated IAsyncEnumerable's IAsyncEnumerator does not trigger the cancellation token of the underlying IAsyncEnumerable.
Specifically, this unit test fails its only ...
0
votes
0
answers
28
views
Angular cancells requests that last longer than 1s after page refresh
I have an issue that appears recently when refreshing page. After page refresh outgoing requests are cancelled after 1s, if complete under 1s everything works fine. After page loaded requests are not ...
0
votes
1
answer
138
views
What the fundamental difference between an async code polling a cancellation token and registering a callback to be executed when the caller requests?
I'm watching (not for the first time) Working with Asynchrony Generically: A Tour of C++ Executors (part 1 and 2), which is about P2300.
With respect to cancellation support, Eric Niebler says that ...
1
vote
1
answer
677
views
How can I prevent customers from canceling their monthly subscriptions on Stripe until three months have passed?
I am implementing a subscription service using Stripe, and I want to enforce a policy where customers cannot cancel their monthly subscriptions until at least three months have passed since the ...
5
votes
0
answers
735
views
boost.asio: how to cancel awaitable without causing termination?
Consider the following code:
#include <boost/asio/awaitable.hpp>
#include <boost/asio/bind_cancellation_slot.hpp>
#include <boost/asio/cancellation_signal.hpp>
#include <boost/...
1
vote
1
answer
129
views
How to cancel a previously called method when a new instance of that method is called
I have an async method Foo that gets called at various points in the execution of my code, based on events coming in. I need a way to cancel any thread/instance of this method that is running whenever ...
1
vote
0
answers
115
views
Kotlin coroutines exception propagation
I would expect that throwing exception inside any flow will leads to propagation of this exception to coroutine collecting this flow. Nevertheless I'm experiencing quite a different behaviour. For ...
0
votes
1
answer
704
views
How to cancel a kotlin coroutine and make sure it was cancelled
How can I make sure the coroutine was in fact cancelled, and did not just return or was cancelled by other means?
There is an obvious race-condition between checking job state and invoking cancel(). ...
4
votes
1
answer
1k
views
Is an Axum handler cancelled if the requester disconnects?
Consider the scenario where a client makes a request and a handler starts processing it, but then the client disconnects before receiving the response. Does Axum destroy the task associated with that ...
2
votes
1
answer
447
views
How to cancel an async operation properly in React / TypeScript?
I have this to check if my server is alive, polling every 10 seconds for a max of 10 times to see if it's alive.
const wait = (ms: number) => new Promise((res) => setTimeout(res, ms));
export ...
1
vote
0
answers
267
views
Cancel other promise execution on Promise.race reject
I am developing an asynchronous Node.js app that implements Promise.race for a portion of its logic:
async function callDeobfuscator(ast) {
const withTimeout = (promise) => {
let timeoutPid;
...
6
votes
2
answers
3k
views
What is the right way to await cancelling an asyncio task?
The docs for cancel make it sound like you should usually propagate CancelledError exceptions:
Therefore, unlike Future.cancel(), Task.cancel() does not guarantee that the Task will be cancelled, ...
0
votes
0
answers
69
views
How to stop for...of loop immediately after an element is displayed on the page?
I even had to create account on Stackoverflow, because I couldn't find the solution for my problem. I'm a newbie in JS and programming in general. Here's the issue - I have a JS function that plays ...
0
votes
1
answer
409
views
How to cancel primary print dialog from poping up
I try to chancel a print event with pure JavaScript. For this, i have created the following code:
window.addEventListener("beforeprint", e => {
e.preventDefault();
e....
0
votes
2
answers
222
views
Cancel Read from grpc streaming rpc
This concerns the grpc library.
How can I cancel reading the next element from the stream in an bidirectional streaming rpc call on the server without cancelling the stream?
Here is a small code ...
1
vote
2
answers
2k
views
how to stop/cancel withAnimation in SwiftUI
I need to do following. Start a function that will wait 5 seconds and then execute withAnimation block that will last 3 seconds. In this 3 second period value of a variable opacity should get to 0. I ...
1
vote
1
answer
301
views
thread cancelation in pthread in linux environment
I executed the following sample code:
#include <pthread.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
static void * thread_func(void *...
1
vote
1
answer
2k
views
How can one cancel an upload in JupyterLab?
I am uploading several large files via JupyterLab:
How can I cancel the upload?
0
votes
0
answers
18
views
Instant abortion functionality for an arbitrary function that takes time to execute? [duplicate]
I'm experiencing difficulty creating an "abortion function" for a looping function that takes significant time to execute, in JavaScript. My goal is to be able to have some stimulus (or one ...
-1
votes
1
answer
207
views
Javascript: automatically stops all "threads" created by an async function when another function starts
I have multiple async functions that the user can call at any time, but I want to make sure that all previously run functions (and the "threads" they might have spawned) are stopped when a ...
0
votes
1
answer
469
views
Use "remember" to store a function to cancel coroutine jobs
How can I remember a function in Jetpack Compose? I'd like the search function to return another function that will cancel its two jobs so that when the user hits search again it won't start another ...
0
votes
1
answer
150
views
How to interrupt an uncompleted delay in SystemVerilog
I want to apply a different rising and falling delay to a signal using the following code:
timeunit 1ns;
timeprecision 1ps;
parameter real delay_en_rising_us = 100.0; //...
4
votes
1
answer
835
views
Cancelling the token source does not work and Main function gets stuck in Console app
I wrote the following C# code in .NET 6 in a simple console application. It captures "Interrupt" signal (i.e. Ctrl+C) and signals cancellation token source to cancel its token.
Then in Main ...
0
votes
0
answers
171
views
Can't cancel Dapr client request
I'm trying to cancel a long running request on a web api server using a CancellationToken in a call on a DaprClient. I'm basing the code on that found at
"Get started with Dapr" article on ...
0
votes
0
answers
174
views
How to cancel execution of async calls in a map function
I am running a process of extracting codes from pages in a PDF file. The problem is that when I hit the cancel button. The process does not get canceled and keeps reading codes from the file. I am ...
0
votes
2
answers
737
views
How to cancel `setTimeout` after Promisification [duplicate]
I'm using setTimeout as a Promise. But then I cannot cancel it using clearTimeout. THis is my code:
const delay = (ms) => new Promise((res) => setTimeout(res, ms));
delay(1000).then(() => ...
2
votes
3
answers
968
views
How to cancel a task without passing a CancellationTokenSource in .NET?
I have some business logic that does some long calculations, returns a result and doesn't accept any CancellationTokenSources and, accordingly, doesn't check for it's isCancellationRequested property.
...
0
votes
0
answers
97
views
In Android MQTT how to Cancel a Publish request
I am using this Mqtt library in Android:
api 'com.github.hannesa2:paho.mqtt.android:4.1'
I am able to publish requests like this:
import org.eclipse.paho.client.mqttv3.*
...
val message = MqttMessage(...
0
votes
0
answers
591
views
how to cancel a server from client with grpc in c#?
I want to cancel a server created in C# from a client written in C#. However, I will not use cancellation tokens for this. I tried to do it with the help of a flag. I wrote a code that sends true when ...
0
votes
2
answers
1k
views
In JavaScript, how to stop execution of a Promise which lost a Promise.race?
I did not find a straightforward way to stop execution of a Promise when using AbortController. Let me explain.
To await async function _aget_Cards within a time limit defined by timeout parameter, I ...
2
votes
2
answers
715
views
Coroutine cancellation in room database operations
I have a screen with a corresponding ViewModel. This screen is a form to be filled and then recorded in a Room database.
After each insertion, some other tables have to be updated accordingly as well.
...
2
votes
2
answers
126
views
How forcefully end Parallel.Invoke loop?
Inside the Compute function there are heavy, long-lasting calculations (dozens of minutes). I can't edit this function, I don't have access to the source code.
List<Action> parallelActions = new(...
2
votes
2
answers
178
views
Task.WhenAll AggregateException not capturing TaskCancelledException\OperationCanceledException when other tasks faulting
When catching the Task.WhenAll AggregateException the TaskCancelledException is not available when other tasks are faulted. Running below code I get the following output:
TaskException
Caught in ...
1
vote
0
answers
128
views
Cancel movefile operation
I tried to schedule a movefile (using the sysinternals tool movefile) operation to delete "C:\ProgramData\Microsoft\Windows Defender\Definition Updates\Backup" but I forgot the quotes and ...
0
votes
1
answer
116
views
Neo4j throwing a ProtocolException when cancelling a transaction
Using neo4j as the db for an api, if a user makes repeated requests using the same or similar parameters (for example, they're requesting many pages of data by scrolling through a list and only the ...