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


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

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


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

示例1: None

Future<Option<int64_t> > GroupProcess::session()
{
    if (error.isSome()) {
        Promise<Option<int64_t> > promise;
        promise.fail(error.get());
        return promise.future();
    } else if (state != CONNECTED) {
        return None();
    }

    return Option<int64_t>::some(zk->getSessionId());
}
开发者ID:nadirabid,项目名称:mesos,代码行数:12,代码来源:group.cpp

示例2:

TEST(FutureTest, RecoverFailed)
{
  Promise<int> promise;

  Future<string> future = promise.future()
    .then([]() -> string {
      return "hello";
    })
    .recover([](const Future<string>&) -> string {
      return "world";
    });

  promise.fail("Failure");

  AWAIT_EQ("world", future);
}
开发者ID:GrovoLearning,项目名称:mesos,代码行数:16,代码来源:future_tests.cpp

示例3: stringify

TEST(FutureTest, Stringify)
{
  Future<bool> future;
  EXPECT_EQ("Abandoned", stringify(future));

  {
    Owned<Promise<bool>> promise(new Promise<bool>());
    future = promise->future();
    promise.reset();
    EXPECT_EQ("Abandoned", stringify(future));
  }

  {
    Owned<Promise<bool>> promise(new Promise<bool>());
    future = promise->future();
    promise->future().discard();
    promise.reset();
    EXPECT_EQ("Abandoned (with discard)", stringify(future));
  }

  {
    Promise<bool> promise;
    future = promise.future();
    EXPECT_EQ("Pending", stringify(future));
    promise.future().discard();
    EXPECT_EQ("Pending (with discard)", stringify(future));
  }

  {
    Promise<bool> promise;
    future = promise.future();
    promise.set(true);
    EXPECT_EQ("Ready", stringify(future));
  }

  {
    Promise<bool> promise;
    future = promise.future();
    promise.future().discard();
    promise.set(true);
    EXPECT_EQ("Ready (with discard)", stringify(future));
  }

  {
    Promise<bool> promise;
    future = promise.future();
    promise.fail("Failure");
    EXPECT_EQ("Failed: Failure", stringify(future));
  }

  {
    Promise<bool> promise;
    future = promise.future();
    promise.future().discard();
    promise.fail("Failure");
    EXPECT_EQ("Failed (with discard): Failure", stringify(future));
  }

  {
    Promise<bool> promise;
    future = promise.future();
    promise.discard();
    EXPECT_EQ("Discarded", stringify(future));
  }

  {
    Promise<bool> promise;
    future = promise.future();
    promise.future().discard();
    promise.discard();
    EXPECT_EQ("Discarded (with discard)", stringify(future));
  }
}
开发者ID:GrovoLearning,项目名称:mesos,代码行数:73,代码来源:future_tests.cpp


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