proxygen
AsyncTest.cpp File Reference
#include <folly/executors/Async.h>
#include <folly/executors/ManualExecutor.h>
#include <folly/portability/GTest.h>
#include <memory>

Go to the source code of this file.

Functions

 TEST (AsyncFunc, manual_executor)
 
 TEST (AsyncFunc, value_lambda)
 
 TEST (AsyncFunc, void_lambda)
 
 TEST (AsyncFunc, moveonly_lambda)
 

Function Documentation

TEST ( AsyncFunc  ,
manual_executor   
)

Definition at line 25 of file AsyncTest.cpp.

References folly::async(), EXPECT_EQ, EXPECT_FALSE, f, folly::getCPUExecutor(), and folly::setCPUExecutor().

25  {
26  auto x = std::make_shared<ManualExecutor>();
27  auto oldX = getCPUExecutor();
29  auto f = async([] { return 42; });
30  EXPECT_FALSE(f.isReady());
31  x->run();
32  EXPECT_EQ(42, f.value());
33  setCPUExecutor(oldX);
34 }
Definition: InvokeTest.cpp:58
auto f
auto async(F &&fn)
Definition: Async.h:24
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::shared_ptr< Executor > getCPUExecutor()
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
void setCPUExecutor(std::weak_ptr< Executor > executor)
TEST ( AsyncFunc  ,
value_lambda   
)

Definition at line 36 of file AsyncTest.cpp.

References folly::async(), EXPECT_EQ, and folly::gen::move.

36  {
37  auto lambda = [] { return 42; };
38  auto future = async(lambda);
39  EXPECT_EQ(42, std::move(future).get());
40 }
auto async(F &&fn)
Definition: Async.h:24
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
TEST ( AsyncFunc  ,
void_lambda   
)

Definition at line 42 of file AsyncTest.cpp.

References folly::async(), EXPECT_EQ, and folly::gen::move.

42  {
43  auto lambda = [] { /*do something*/ return; };
44  auto future = async(lambda);
45  // Futures with a void returning function, return Unit type
46  EXPECT_EQ(typeid(Unit), typeid(std::move(future).get()));
47 }
auto async(F &&fn)
Definition: Async.h:24
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
TEST ( AsyncFunc  ,
moveonly_lambda   
)

Definition at line 49 of file AsyncTest.cpp.

References folly::async(), EXPECT_EQ, and folly::gen::move.

49  {
50  auto lambda = [] { return std::make_unique<int>(42); };
51  auto future = async(lambda);
52  EXPECT_EQ(42, *std::move(future).get());
53 }
auto async(F &&fn)
Definition: Async.h:24
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567