cancellation

Abort ecmascript7 async function

荒凉一梦 提交于 2019-12-23 12:34:05
问题 Is there a way to cancel a ES7 async function? In this example, on click, I want to abort async function call before calling new. async function draw(){ for(;;){ drawRandomRectOnCanvas(); await sleep(100); } } function sleep(t){ return new Promise(cb=>setTimeout(cb,t)); } let asyncCall; window.addEventListener('click', function(){ if(asyncCall) asyncCall.abort(); // this dont works clearCanvas(); asyncCall = draw(); }); 回答1: There's nothing built in to JavaScript yet, but you could easily

Cancel a promise when a component is unmounted in ReactJS

不想你离开。 提交于 2019-12-23 06:58:52
问题 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 Promise((resolve, reject) => { setTimeout(() => resolve("PROMISE COMPLETED "+this.props.id),6000) }) } componentDidMount(){ this.prom.then((success) => { console.log(success) }) } componentWillUnmount(){ console.log("unmounted") } onClick(e){ e.preventDefault() this.props.remove

What is the Correct HTTP Status Code for a Cancelled Request

前提是你 提交于 2019-12-23 06:50:32
问题 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? 回答1: To be consistent I would suggest 400 Bad Request now if your backend apps are capable of identifying when the client gets disconnected or if you reject or close the connection, probably you could return Nginx' non-standard code 499 or 444. 499 Client Closed Request Used when the

How to cancel Stream.ReadAsync?

守給你的承諾、 提交于 2019-12-23 01:52:58
问题 Why doesn't the code below ever complete if you don't type any input, and why does it still respond to a key being pressed even after the cancellation token has been canceled? // Set up a cancellation token var cancellationSource = new CancellationTokenSource(); // Cancel the cancellation token after a little bit of time Task.Run(async () => { await Task.Delay(TimeSpan.FromSeconds(2)); cancellationSource.Cancel(); Console.WriteLine("Canceled the cancellation token"); }); // Wait for user

Async/Await equivalent to .ContinueWith with CancellationToken and TaskScheduler.FromCurrentSynchronizationContext() scheduler

谁说我不能喝 提交于 2019-12-23 01:52:55
问题 This is a follow-up to this question. Question : What would be a succinct way to express the following using async / await instead of .ContinueWith() ?: var task = Task.Run(() => LongRunningAndMightThrow()); m_cts = new CancellationTokenSource(); CancellationToken ct = m_cts.Token; var uiTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext(); Task updateUITask = task.ContinueWith(t => UpdateUI(t), ct, TaskContinuationOptions.None, uiTaskScheduler); I'm mainly interested in the case

BackgroundWorker cancellation

自作多情 提交于 2019-12-22 12:27:47
问题 I am using a BackgroundWorker in my winforms app to perform a long running task that occurs in another class (performing database operations). Since all the work is done in another class the cancellation is not as simple. I am using an event in the other class ( GenerateStats ) to update the progress as the background operation completes. I want to do a similar thing with cancelling the operation. I can't just call cancellationPending in the DoWork function because the method would never see

WF 4, WCF, cancel running workflow

↘锁芯ラ 提交于 2019-12-22 11:28:30
问题 Currently have a simple workflow exposed as a service endpoint. The service correlates on the workflow instance id and everything works as expected (2 service calls available ReceiveBegin, Execute). My problem is that I would like the user to be able to cancel the long running part of the workflow by calling another Receive on the workflow. Have had a look at the WorkflowApplication.Cancel but as I am running this as a WCF service it doesn't seem to be available. Documentation seems a bit

When is POSIX thread cancellation not immediate?

淺唱寂寞╮ 提交于 2019-12-21 22:23:54
问题 The POSIX specifies two types for thread cancellation type: PTHREAD_CANCEL_ASYNCHRONOUS , and PTHREAD_CANCEL_DEFERRED (set by pthread_setcanceltype(3) ) determining when pthread_cancel(3) should take effect. By my reading, the POSIX manual pages do not say much about these, but Linux manual page says the following about PTHREAD_CANCEL_ASYNCHRONOUS : The thread can be canceled at any time. (Typically, it will be canceled immediately upon receiving a cancellation request, but the system doesn't

Whether method cancel() in java.util.concurrent.Future should be blocking?

五迷三道 提交于 2019-12-21 19:32:03
问题 I'm trying to implement Future<> interface in my project. But it looks like documentation is a little bit vague for it. From official documentation we can deduce: Method cancel() does not throw exceptions like InterruptedException or ExecutionException. Moreover it has no the variant with timeout. So it looks like, it should NOT be blocking. Documentation says After this method returns, subsequent calls to isDone() will always return true. but boolean isDone() Returns true if this task

Whether method cancel() in java.util.concurrent.Future should be blocking?

丶灬走出姿态 提交于 2019-12-21 19:31:28
问题 I'm trying to implement Future<> interface in my project. But it looks like documentation is a little bit vague for it. From official documentation we can deduce: Method cancel() does not throw exceptions like InterruptedException or ExecutionException. Moreover it has no the variant with timeout. So it looks like, it should NOT be blocking. Documentation says After this method returns, subsequent calls to isDone() will always return true. but boolean isDone() Returns true if this task