本文整理汇总了C++中Promise::discard方法的典型用法代码示例。如果您正苦于以下问题:C++ Promise::discard方法的具体用法?C++ Promise::discard怎么用?C++ Promise::discard使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Promise
的用法示例。
在下文中一共展示了Promise::discard方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readyFuture
TEST(FutureTest, Chain)
{
Future<string> s = readyFuture()
.then(lambda::bind(&second, lambda::_1))
.then(lambda::bind(&third, lambda::_1));
s.await();
ASSERT_TRUE(s.isReady());
EXPECT_EQ("true", s.get());
s = failedFuture()
.then(lambda::bind(&second, lambda::_1))
.then(lambda::bind(&third, lambda::_1));
s.await();
ASSERT_TRUE(s.isFailed());
Promise<bool> promise;
s = pendingFuture(promise.future())
.then(lambda::bind(&second, lambda::_1))
.then(lambda::bind(&third, lambda::_1));
ASSERT_TRUE(s.isPending());
promise.discard();
AWAIT_DISCARDED(s);
}
示例2:
TEST(FutureTest, RecoverDiscarded)
{
Promise<int> promise;
Future<string> future = promise.future()
.then([]() -> string {
return "hello";
})
.recover([](const Future<string>&) -> string {
return "world";
});
promise.discard();
AWAIT_EQ("world", future);
}
示例3: Break
TEST(LoopTest, DiscardIterate)
{
Promise<int> promise;
promise.future().onDiscard([&]() { promise.discard(); });
Future<Nothing> future = loop(
[&]() {
return promise.future();
},
[&](int i) -> ControlFlow<Nothing> {
return Break();
});
EXPECT_TRUE(future.isPending());
future.discard();
AWAIT_DISCARDED(future);
EXPECT_TRUE(promise.future().hasDiscard());
}
示例4: 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));
}
}