本文整理汇总了C++中Future::unwrap方法的典型用法代码示例。如果您正苦于以下问题:C++ Future::unwrap方法的具体用法?C++ Future::unwrap怎么用?C++ Future::unwrap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Future
的用法示例。
在下文中一共展示了Future::unwrap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
// Makes sure that the unwrap call also works when the promise was not yet
// fulfilled, and that the returned Future<T> becomes ready once the promise
// is fulfilled.
TEST(Unwrap, futureNotReady) {
Promise<Future<int>> p;
Future<Future<int>> future = p.getFuture();
Future<int> unwrapped = future.unwrap();
// Sanity - should not be ready before the promise is fulfilled.
ASSERT_FALSE(unwrapped.isReady());
// Fulfill the promise and make sure the unwrapped future is now ready.
p.setValue(makeFuture(5484));
ASSERT_TRUE(unwrapped.isReady());
EXPECT_EQ(5484, unwrapped.value());
}
示例2: makeFuture
// Makes sure that unwrap() works when chaning Future's commands.
TEST(Unwrap, chainCommands) {
Future<Future<int>> future = makeFuture(makeFuture(5484));
auto unwrapped = future.unwrap().then([](int i){ return i; });
EXPECT_EQ(5484, unwrapped.value());
}