Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Filter by
Sorted by
Tagged with
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 ...
TheBrenny's user avatar
  • 545
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 ...
Prexi's user avatar
  • 13
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 ...
Sumit Anand's user avatar
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 ...
Charles Duffy's user avatar
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 ...
FKus's user avatar
  • 41
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 ...
bitchwhocodes's user avatar
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 ...
Chris Davies's user avatar
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....
alx9r's user avatar
  • 4,343
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 ...
Sunib's user avatar
  • 352
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 ...
vss's user avatar
  • 21
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 &...
Arokh's user avatar
  • 684
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 ...
Nighto's user avatar
  • 4,262
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 ...
Arash's user avatar
  • 4,387
-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, ...
Brayce's user avatar
  • 1
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 ...
FlamingDrake's user avatar
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 ...
Bogey's user avatar
  • 5,916
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 ...
Jakub's user avatar
  • 1
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 ...
Enlico's user avatar
  • 30.2k
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 ...
javed iqbal's user avatar
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/...
Jean-Michaël Celerier's user avatar
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 ...
Nicholas van Huyssteen's user avatar
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 ...
David's user avatar
  • 29
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(). ...
milan's user avatar
  • 2,545
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 ...
kmdreko's user avatar
  • 65.3k
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 ...
Lance Pollard's user avatar
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; ...
GRoutar's user avatar
  • 1,455
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, ...
Joseph Garvin's user avatar
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 ...
TotalDistruct's user avatar
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....
Angled's user avatar
  • 65
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 ...
Maximilian Mordig's user avatar
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 ...
Gregor Sotošek's user avatar
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 *...
tahzibi.jafar's user avatar
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?
Franck Dernoncourt's user avatar
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 ...
Yodabird19's user avatar
-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 ...
tobiasBora's user avatar
  • 2,594
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 ...
t3chb0t's user avatar
  • 19.3k
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; //...
Du mmyTransistor's user avatar
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 ...
Shishir Gupta's user avatar
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 ...
Greg Arzoomanian's user avatar
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 ...
Qasim Ali's user avatar
  • 607
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(() => ...
rostamiani's user avatar
  • 3,365
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. ...
David Oganesyan's user avatar
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(...
M. Usman Khan's user avatar
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 ...
anonimusBird's user avatar
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 ...
Youri Malleck-Ahmed's user avatar
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. ...
Ait-Gacem Nabil's user avatar
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(...
CeD's user avatar
  • 23
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 ...
clonesegg's user avatar
  • 245
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 ...
Jacoblightning3's user avatar
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 ...
pilsdumps's user avatar
  • 617

1
2 3 4 5
15