当前位置: 首页>>代码示例>>C++>>正文


C++ Promise::setException方法代码示例

本文整理汇总了C++中Promise::setException方法的典型用法代码示例。如果您正苦于以下问题:C++ Promise::setException方法的具体用法?C++ Promise::setException怎么用?C++ Promise::setException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Promise的用法示例。


在下文中一共展示了Promise::setException方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: test_promise

void test_promise() {
  Promise<bool> p;

  auto f = p.getFuture();
  try {
    p.getFuture();
    ok(false, "should throw");
  } catch (const std::logic_error& exc) {
    ok(!strcmp(exc.what(), "Future already obtained"), "can't getFuture twice");
  }
  ok(!f.isReady(), "not yet ready");

  p.setValue(true);
  try {
    p.setValue(false);
    ok(false, "should throw");
  } catch (const std::logic_error& exc) {
    ok(!strcmp(exc.what(), "Promise already fulfilled"),
       "can't setValue twice");
  }

  ok(f.isReady(), "now ready");
  ok(f.get() == true, "got our true value");

  Promise<std::string> s;
  s.setException(std::make_exception_ptr(std::runtime_error("boo")));
  auto f2 = s.getFuture();
  ok(f2.result().hasError(), "holds an error");
  try {
    f2.get();
  } catch (const std::runtime_error& exc) {
    ok(!strcmp(exc.what(), "boo"), "has boo string");
  }
}
开发者ID:Stevenzwzhai,项目名称:watchman,代码行数:34,代码来源:FutureTest.cpp

示例2: catch

TEST(Promise, setException) {
    {
        Promise<Unit> p;
        auto f = p.getFuture();
        p.setException(eggs);
        EXPECT_THROW(f.value(), eggs_t);
    }
    {
        Promise<Unit> p;
        auto f = p.getFuture();
        try {
            throw eggs;
        } catch (...) {
            p.setException(exception_wrapper(std::current_exception()));
        }
        EXPECT_THROW(f.value(), eggs_t);
    }
}
开发者ID:BocaiFire,项目名称:folly,代码行数:18,代码来源:PromiseTest.cpp

示例3: move

  Future<int> future_throwing() {
    Promise<int> p;
    auto f = p.getFuture();

    Xception x;
    x.errorCode = 32;
    x.message = "test";

    p.setException(x);

    return std::move(f);
  }
开发者ID:andrianyablonskyy,项目名称:fbthrift,代码行数:12,代码来源:FutureTest.cpp

示例4:

  Future<Unit> future_voidThrowing() override {
    Promise<Unit> p;
    auto f = p.getFuture();

    Xception x;
    x.errorCode = 42;
    x.message = "test2";

    p.setException(x);

    return f;
  }
开发者ID:facebook,项目名称:fbthrift,代码行数:12,代码来源:FutureTest.cpp

示例5: collect

TEST(Collect, collectVariadicWithException) {
  Promise<bool> pb;
  Promise<int> pi;
  Future<bool> fb = pb.getFuture();
  Future<int> fi = pi.getFuture();
  auto f = collect(std::move(fb), std::move(fi));
  pb.setValue(true);
  EXPECT_FALSE(f.isReady());
  pi.setException(eggs);
  EXPECT_TRUE(f.isReady());
  EXPECT_TRUE(f.getTry().hasException());
  EXPECT_THROW(f.get(), eggs_t);
}
开发者ID:derek-zhang,项目名称:folly,代码行数:13,代码来源:CollectTest.cpp

示例6:

TEST(SemiFuture, MakeSemiFutureFromFutureWithTry) {
  Promise<int> p;
  auto f = p.getFuture();
  auto sf = std::move(f).semi().defer([&](Try<int> t) {
    if (auto err = t.tryGetExceptionObject<std::logic_error>()) {
      return Try<std::string>(err->what());
    }
    return Try<std::string>(
        make_exception_wrapper<std::logic_error>("Exception"));
  });
  p.setException(make_exception_wrapper<std::logic_error>("Try"));
  auto tryResult = std::move(sf).get();
  ASSERT_EQ(tryResult.value(), "Try");
}
开发者ID:simpkins,项目名称:folly,代码行数:14,代码来源:SemiFutureTest.cpp

示例7: collectAll

TEST(Collect, collectAllVariadicWithException) {
  Promise<bool> pb;
  Promise<int> pi;
  Future<bool> fb = pb.getFuture();
  Future<int> fi = pi.getFuture();
  bool flag = false;
  collectAll(std::move(fb), std::move(fi))
    .then([&](std::tuple<Try<bool>, Try<int>> tup) {
      flag = true;
      EXPECT_TRUE(std::get<0>(tup).hasValue());
      EXPECT_EQ(std::get<0>(tup).value(), true);
      EXPECT_TRUE(std::get<1>(tup).hasException());
      EXPECT_THROW(std::get<1>(tup).value(), eggs_t);
    });
  pb.setValue(true);
  EXPECT_FALSE(flag);
  pi.setException(eggs);
  EXPECT_TRUE(flag);
}
开发者ID:lamoreauxdy,项目名称:coral,代码行数:19,代码来源:CollectTest.cpp

示例8: transportActive

TEST_F(ObservingHandlerTest, ConnectErrorHandlerDeletion) {
  // Test when an error occurs while fetching the broadcast handler
  // after the handler is deleted
  InSequence dummy;

  EXPECT_CALL(*prevHandler, transportActive(_))
      .WillOnce(Invoke([&](MockBytesToBytesHandler::Context* ctx) {
        ctx->fireTransportActive();
      }));
  // Verify that ingress is paused
  EXPECT_CALL(*prevHandler, transportInactive(_)).WillOnce(Return());
  Promise<BroadcastHandler<int, std::string>*> promise;
  EXPECT_CALL(pool, mockGetHandler(_))
      .WillOnce(Return(makeMoveWrapper(promise.getFuture())));

  // Initialize the pipeline
  pipeline->transportActive();

  // Delete the handler and then inject an error
  pipeline.reset();
  promise.setException(std::exception());
}
开发者ID:AmineCherrai,项目名称:wangle,代码行数:22,代码来源:ObservingHandlerTest.cpp


注:本文中的Promise::setException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。