cancellation

How to cancel GetConsumingEnumerable() on BlockingCollection

痞子三分冷 提交于 2019-12-21 04:21:31
问题 In the following code I'm using the CancellationToken to wake up the GetConsumingEnumerable() when the producer is not producing and I want to break out of the foreach and exit the Task. But I dont see IsCancellationRequested being logged and my Task.Wait(timeOut) waits for the full timeOut period. What am I doing wrong? userToken.Task = Task.Factory.StartNew(state => { userToken.CancelToken = new CancellationTokenSource(); foreach (var broadcast in userToken.BroadcastQueue

How to cancel GetConsumingEnumerable() on BlockingCollection

早过忘川 提交于 2019-12-21 04:21:05
问题 In the following code I'm using the CancellationToken to wake up the GetConsumingEnumerable() when the producer is not producing and I want to break out of the foreach and exit the Task. But I dont see IsCancellationRequested being logged and my Task.Wait(timeOut) waits for the full timeOut period. What am I doing wrong? userToken.Task = Task.Factory.StartNew(state => { userToken.CancelToken = new CancellationTokenSource(); foreach (var broadcast in userToken.BroadcastQueue

Atomically cancel asio asynchronious timer from another thread

限于喜欢 提交于 2019-12-19 10:51:58
问题 I have a boost deadline_timer which runs periodically (as in example http://www.boost.org/doc/libs/1_35_0/doc/html/boost_asio/tutorial/tuttimer3/src.html): #include <iostream> #include <boost/asio.hpp> #include <boost/bind.hpp> #include <boost/date_time/posix_time/posix_time.hpp> void print(const boost::system::error_code& /*e*/, boost::asio::deadline_timer* t) { t->expires_at(t->expires_at() + boost::posix_time::seconds(1)); t->async_wait(boost::bind(print, boost::asio::placeholders::error,

Cancellable set of asynchronous operations with progress reporting in iOS

妖精的绣舞 提交于 2019-12-19 09:05:29
问题 Suppose that I use another SDK (which I do not have control of) with an API that imports 1 file asynchronously, and calls a completion callback on completion. The following is an example API. func importFile(filePath: String, completion: () -> Void) I need to import 10 files (one by one) using this API, but I need it to be cancellable, e.g. after Files 1,2,3 has been successfully imported, while File 4 is being imported, I want to be able to cancel the whole set of operations (import of the

Server based SwingWorker does not Stop

◇◆丶佛笑我妖孽 提交于 2019-12-18 07:14:47
问题 I have a boolean variable to control the execution of the server (start/stop) : private boolean ecoute=true; here is my class: sw=new SwingWorker<String,Void> (){ protected String doInBackground() throws Exception { try { server = new ServerSocket(Integer.parseInt(port.getText())); String str1="waiting for connexion.."; String str2="Connexion ok"; log.append(str1+"\n"); PrintWriter out=null; BufferedReader in=null; Socket socClient=null; while(ecoute){ socClient = server.accept(); log.append

HttpRequest not aborted (cancelled) on browser abort in ASP.NET Core MVC

一个人想着一个人 提交于 2019-12-18 03:14:41
问题 I wrote the following MVC Controller to test cancellation functionality: class MyController : Controller { [HttpGet("api/CancelTest")] async Task<IActionResult> Get() { await Task.Delay(1000); CancellationToken token = HttpContext.RequestAborted; bool cancelled = token.IsCancellationRequested; logger.LogDebug(cancelled.ToString()); return Ok(); } } Say, I want to cancel the request, so the value ' true ' is logged in the controller action above. This is possible server-side if the server

Status of cancellable promises

ⅰ亾dé卋堺 提交于 2019-12-18 02:30:49
问题 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 ‘standard’ promises. By now looks like the feature is implemented in bluebird, but as a library developer I don’t want to clutter my package with a full promise implementation. What I’d like to do is simply pass a promise-like and support the cancellation-spec. Where could I find this information?

How to cancel a running task?

风格不统一 提交于 2019-12-17 21:21:50
问题 I want to cancel a running task (when the users presses the escape key). when i click on "escape" key Form_KeyDown run but doesn't cancel task! CancellationTokenSource tokenSource = new CancellationTokenSource(); CancellationToken token=new CancellationToken(); private async void Search_Button_ClickAsync(object sender, EventArgs e) { token = tokenSource.Token; await (Task.Factory.StartNew(() => { //...my program }, token)); private void Form_KeyDown(object sender, KeyEventArgs e) { if (e

Python code to cancel a running Oracle SQL Query

岁酱吖の 提交于 2019-12-11 19:46:27
问题 I have the following python code which runs multiple SQL Queries in Oracle database and combines them into one dataframe. The queries exist in a txt file and every row is a separate SQL query. The loop runs sequentially the queries. I want to cancel any SQL queries that run for more than 10 secs so as not to create an overhead in the database. The following code doesnt actually me give the results that i want. More specifically this bit of the code really help me on my issue: if (time.time()

cancel a transaction in MySQL InnoDB instead of commit or rollback

帅比萌擦擦* 提交于 2019-12-11 19:14:17
问题 I am using a transaction in a MySQL InnoDB database to perform 2 inserts. However, if the first insert fails, I would like to simply "cancel" the transaction. Is there a good approach to "cancel" the transaction rather than using commit or rollback ? For example, in php, I am doing the following: $connection->beginTransaction(); $affectedRows = $tableOne->insertIgnore('example data'); if ($affectedRows == 0) { $connection->rollback(); } else { $tableTwo->insert('more example data');