std :: async与std :: future_status :: timeout,仅在iOS上的每个备用时间超时

时间:2016-11-25 09:59:37

标签: ios c++11 clang c++14 stdasync

我在我的应用的std::async部分使用C++来执行heavy transaction,如果网络出现问题,可能需要花费很长时间。{1}}所以我使用std::async结合std::future等待超时设置,这可以避免在交易耗时很长时挂断。每次用户点击UI上的某个按钮时都会调用它。

我的C++代码在4个不同的平台上使用,即iOS, Android, OSX & Windows。以下是我使用std::async来执行此操作的方法。

//Do the operation in async
std::future<size_t> my_future_result(std::async(std::launch::async, [this]() {
  size_t result = someHeavyFunctionCall();
  return result;
}));

//try to get the status of the operation after a time_out
std::future_status my_future_status = my_future_result.wait_for(std::chrono::milliseconds(some_time_out));
if (my_future_status == std::future_status::timeout) {
  std::cout << "it times out every alternate time on ios only" << std::endl;
}
else if (my_future_status == std::future_status::ready) {
  if (my_future_result.get() > 0)
      //we are all fine
}

以上std::async & std::future_status技术适用于所有平台。仅在iOS上,我遇到问题,future在用户点击按钮的每个备用时间超时。

我使用std::async & std::future_status的方式是否应该纠正?什么可能是错的?我试图搜索这个很多。我没有得到std::async尚未为所有平台做好准备的信息。我是否遇到了std::async iOS上出现的问题?

我是基于async+futures C++编程的新手。如果我在这里做了一个明显的错误,请告诉我

0 个答案:

没有答案