cancellation

How to cancel timeout inside of Javascript Promise?

蹲街弑〆低调 提交于 2019-12-31 20:06:31
问题 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 myPromise=timeout(3000); myPromise.then(function(result) { console.log(result); // timeout done }) Fairly straightforward but I was wondering how would I go about canceling my timeout before the promise resolves. timeout returns Promise object hence I loose access to value

How to cancel timeout inside of Javascript Promise?

本小妞迷上赌 提交于 2019-12-31 20:06:30
问题 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 myPromise=timeout(3000); myPromise.then(function(result) { console.log(result); // timeout done }) Fairly straightforward but I was wondering how would I go about canceling my timeout before the promise resolves. timeout returns Promise object hence I loose access to value

What exactly is a cancellation point?

风流意气都作罢 提交于 2019-12-30 01:54:07
问题 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() function. Apparently this is a cancellation point. So when I call write(), I can see that another thread may start processing (so my code switches from the writing thread to another thread), this usually happens when the write-to buffer is full and

What exactly is a cancellation point?

混江龙づ霸主 提交于 2019-12-30 01:54:06
问题 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() function. Apparently this is a cancellation point. So when I call write(), I can see that another thread may start processing (so my code switches from the writing thread to another thread), this usually happens when the write-to buffer is full and

Cancel call to 'HttpClient.SendAsync()'

旧街凉风 提交于 2019-12-29 08:04:50
问题 Is it possible to cancel a call to HttpClient.SendAsync() ? I'm sending some data like this: var requestMessage = new HttpRequestMessage(HttpMethod.Post, "some url"); var multipartFormDataContent = new MultipartFormDataContent(); // ... construction of the MultipartFormDataContent. It contains form data + picture file requestMessage.Content = multipartFormDataContent; var response = await client.SendAsync(requestMessage).ConfigureAwait(false); This code works perfectly, but I need to be able

Stopping a Thread, ManualResetEvent, volatile boolean or cancellationToken

给你一囗甜甜゛ 提交于 2019-12-29 07:13:09
问题 I have a Thread (STAThread) in a Windows Service, which performs a big amount of work. When the windows service is restarted I want to stop this thread gracefully. I know of a couple of ways A volatile boolean ManualResetEvent CancellationToken As far as I have found out Thread.Abort is a no go... What is the best practice ? The work is perfomed in another class than the one where the thread is started, so it is necessary to either introduce a cancellationToken parameter in a constructor or

Cancel NetworkStream.ReadAsync using TcpListener

℡╲_俬逩灬. 提交于 2019-12-28 18:39:03
问题 Consider the following simplified example (ready to roll in LinqPad, elevated account required): void Main() { Go(); Thread.Sleep(100000); } async void Go() { TcpListener listener = new TcpListener(IPAddress.Any, 6666); try { cts.Token.Register(() => Console.WriteLine("Token was canceled")); listener.Start(); using(TcpClient client = await listener.AcceptTcpClientAsync() .ConfigureAwait(false)) using(var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5))) { var stream=client.GetStream

Error: The operation was canceled

吃可爱长大的小学妹 提交于 2019-12-24 14:03:59
问题 I'm using this code snippet to do an async query with a cancellation token: var _client = new HttpClient( /* some setthngs */ ); _client.GetAsync(someUrl, cancellationToken).ContinueWith(gettingTask => { cancellationToken.ThrowIfCancellationRequested(); SomeStuffToDO(); }, TaskScheduler.FromCurrentSynchronizationContext()); }, TaskScheduler.FromCurrentSynchronizationContext()); But, when operation get cancelled, cancellationToken.ThrowIfCancellationRequested(); throws an exception. I know

How to cancel custom awaitable

为君一笑 提交于 2019-12-24 10:44:45
问题 I've read Stephen Toub's blog about making a custom awaitable for SocketAsyncEventArgs. This works all fine. But what I need is a cancellable awaitable and the blog doesn't cover this topic. Also Stephen Cleary unfortunately doesn't cover in his book how to cancel async methods that don't support cancellation. I tried to implement it myself, but I fail with the TaskCompletionSource and Task.WhenAny because with the awaitable I'm not actually awaiting a task. This is what I would like to have:

Cancel RX.Net Observer's ongoing OnNext methods

时光总嘲笑我的痴心妄想 提交于 2019-12-24 00:29:13
问题 As described in my original question (see Correlate interdependent Event Streams with RX.Net) I have an RX.net event stream that shall only call the observer's OnNext method as long as a certain other event is not triggered (basically 'Handle Change-* Events as long as the system is connected, pause while disconnected and re-start handling of the Change-* events once the system has re-connected). However, while this works smoothly with new events, how would I cancel / signal cancellation to