本文整理汇总了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());
}
示例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);
}
示例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));
}
}