2 * Copyright 2017 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <folly/executors/Async.h>
18 #include <folly/executors/ManualExecutor.h>
19 #include <folly/portability/GTest.h>
23 using namespace folly;
25 TEST(AsyncFunc, manual_executor) {
26 auto x = std::make_shared<ManualExecutor>();
27 auto oldX = getCPUExecutor();
29 auto f = async([] { return 42; });
30 EXPECT_FALSE(f.isReady());
32 EXPECT_EQ(42, f.value());
36 TEST(AsyncFunc, value_lambda) {
37 auto lambda = [] { return 42; };
38 auto future = async(lambda);
39 EXPECT_EQ(42, future.get());
42 TEST(AsyncFunc, void_lambda) {
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(future.get()));
49 TEST(AsyncFunc, moveonly_lambda) {
50 auto lambda = [] { return std::make_unique<int>(42); };
51 auto future = async(lambda);
52 EXPECT_EQ(42, *future.get());