future

std::async decaying(losing) rvalue reference in Visual Studio 2012 Update 2. Any workarounds?

陌路散爱 提交于 2019-12-23 08:40:02
问题 Consider the below code: #include <memory> #include <future> using namespace std; template <typename T, typename Work> void Test2(future<T> f, Work w) { async([](future<T> && f, Work w) {}, move(f), move(w)); } int main() { future<int> x = std::async([]()->int{ std::this_thread::sleep_for(std::chrono::microseconds(200)); return 10; }); Test2(std::move(x), [](int x){}); return 0; } The above, fails with the following compiler error: Error 1 error C2664: 'void Test2::::operator ()(std::future<

std::async decaying(losing) rvalue reference in Visual Studio 2012 Update 2. Any workarounds?

情到浓时终转凉″ 提交于 2019-12-23 08:39:17
问题 Consider the below code: #include <memory> #include <future> using namespace std; template <typename T, typename Work> void Test2(future<T> f, Work w) { async([](future<T> && f, Work w) {}, move(f), move(w)); } int main() { future<int> x = std::async([]()->int{ std::this_thread::sleep_for(std::chrono::microseconds(200)); return 10; }); Test2(std::move(x), [](int x){}); return 0; } The above, fails with the following compiler error: Error 1 error C2664: 'void Test2::::operator ()(std::future<

gRPC future callback got exception:StatusRuntimeException: CANCELLED

不想你离开。 提交于 2019-12-23 04:28:34
问题 io.grpc.StatusRuntimeException: CANCELLED at io.grpc.Status.asRuntimeException(Status.java:539) at io.grpc.stub.ClientCalls$UnaryStreamToFuture.onClose(ClientCalls.java:439) at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:422) at io.grpc.internal.ClientCallImpl.access$100(ClientCallImpl.java:74) at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:508) at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$700(ClientCallImpl

ThingsBoard: plot timeseries with future timestamps in a chart widget

梦想的初衷 提交于 2019-12-23 03:58:10
问题 I've been having some troubles with TB in the last days. I have a generic variable (let's assume, for example, the external temperature), which measures are acquired at realtime using MQTT and tb-gateway. I also have the variable forecasts for a given future time period, acquired via MQTT from a Python module which performs the forecasting. I wish to plot in the same graph both the data acquired at realtime and the forecasted trend for a given time period (let's say for the next 24 hours),

Scala: completing a Future when other Futures are completed

会有一股神秘感。 提交于 2019-12-23 02:03:44
问题 I have references to n Future instances f1,.....fn . Is it possible to use Future.apply to create a Future that would complete only when at least one of the n Futures completes, without constantly checking their completion status, but instead by some more efficient way, maybe a callback? 回答1: Future.firstCompletedOf(Seq(f1, ..., fn)) Asynchronously and non-blockingly returns a new Future to the result of the first future in the list that is completed. 来源: https://stackoverflow.com/questions

Scala: completing a Future when other Futures are completed

五迷三道 提交于 2019-12-23 02:03:24
问题 I have references to n Future instances f1,.....fn . Is it possible to use Future.apply to create a Future that would complete only when at least one of the n Futures completes, without constantly checking their completion status, but instead by some more efficient way, maybe a callback? 回答1: Future.firstCompletedOf(Seq(f1, ..., fn)) Asynchronously and non-blockingly returns a new Future to the result of the first future in the list that is completed. 来源: https://stackoverflow.com/questions

Java Concurrency: Is cancelling Futures necessary for them to be Garbage Collected?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-22 11:18:59
问题 I am writing some code where I might need to create an unbounded number of future objects (java.util.concurrent.Future). But I am worried about running out of memory at some point. Couple of questions here: Does the jvm know that once the future has completed, it is not being refernced anywhere and therefore is eligible for GC (even if the thread within which it was created is still alive and running)? Ideally, I wouldn't want to keep track of these futures themselves. But if I do keep the

Break the flow of CompletableFuture

拜拜、爱过 提交于 2019-12-22 06:45:23
问题 I have certain flow that runs async using the CompletableFuture , e.g.: foo(...) .thenAccept(aaa -> { if (aaa == null) { break! } else { ... } }) .thenApply(aaa -> { ... }) .thenApply(... So if my foo() returns null (in a future) I need to break very soon, otherwise, the flow continue. For now I have to check for null all the way, in every future block; but that is ugly. Would this be possible with CompletableFuture ? EDIT With CompletableFuture you can define your flow of async tasks, that

Who is responsible for the shared state of futures and promises

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-22 05:03:43
问题 Who owns the shared state in futures and promises? In particular who is responsible for the construction and deletion of the shared state in these classes? Or is the shared state supposed to be reference counted? I am not able to get an answer by reading the docs for these on cppreference. The way I was thinking about it the easiest thing to do would be to have the std::promise class be responsible for the creation of the shared state, but then hand it off to the std::future that is fetched

Can each Iteration of a for loop/for_each be done in parallel? (C++11)

痞子三分冷 提交于 2019-12-22 04:05:36
问题 I'm iterating over a vector of structs and processing each struct individually. It looks something like this: for_each(begin(data),end(data),DoTask); //assume "data" is std::vector<DataT> //assume DoTask is a function that takes a DataT by reference The code is significantly slow because DoTask connects to particular websites and analyzes HTML. What would be the best way to speed this up? My goal is to analyze multiple DataTs at the same time. I'm very new to threading, but std::async and std