Commit 242186f5 authored by Pranav Thulasiram Bhat's avatar Pranav Thulasiram Bhat Committed by Facebook GitHub Bot

Implement Uniform initialization constructor for Async

Summary:
Use template parameter packing in the constructor to make the implicit constructor usable for the uniform intialization of container types.

We want the return syntax to be unchanged to the extent possible when annotating functions.

Reviewed By: A5he

Differential Revision: D21290083

fbshipit-source-id: 140bbaf987cdfd673046e92dd263b5180c8e9daa
parent 9f336fad
......@@ -66,8 +66,8 @@ template <typename T>
class [[nodiscard]] Async {
public:
// General use constructor
template <typename U>
/* implicit */ Async(U && val) : val_(std::forward<U>(val)) {}
template <typename... Us>
/* implicit */ Async(Us && ... val) : val_(std::forward<Us>(val)...) {}
// Move constructor to allow eager-return of async without using await
template <typename U>
......
......@@ -2615,31 +2615,21 @@ async::Async<folly::Optional<std::string>> getOptionalAsyncString() {
// Async<folly::Optional<std::string>>
return getAsyncString();
}
async::Async<std::tuple<int, float, std::string>> getTuple() {
return {0, 0.0, "0"};
}
} // namespace
TEST(FiberManager, asyncAwait) {
folly::EventBase evb;
auto& fm = getFiberManager(evb);
EXPECT_NO_THROW(fm.addTaskFuture([&]() {
EXPECT_NO_THROW(async::await(getAsyncNothing()));
EXPECT_EQ(getString(), async::await(getAsyncString()));
EXPECT_EQ(
getString(), *async::await(getOptionalAsyncString()));
})
.getVia(&evb));
}
TEST(FiberManager, asyncInitAwait) {
folly::EventBase evb;
auto& fm = getFiberManager(evb);
EXPECT_NO_THROW(
fm.addTaskFuture([&]() { async::init_await(getAsyncNothing()); })
.getVia(&evb));
EXPECT_EQ(
getString(),
fm.addTaskFuture([&]() { return async::init_await(getAsyncString()); })
fm.addTaskFuture([&]() {
async::init_await(getAsyncNothing());
EXPECT_EQ(getString(), async::init_await(getAsyncString()));
EXPECT_EQ(getString(), *async::init_await(getOptionalAsyncString()));
async::init_await(getTuple());
})
.getVia(&evb));
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment