Commit 81798e75 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Let FutureSplitter hold a KeepAlive

Summary: [Folly] Let `FutureSplitter` hold a `Executor::KeepAlive<>` rather than a raw `Executor*`.

Reviewed By: andriigrynenko

Differential Revision: D15835712

fbshipit-source-id: c0d5b4271212708657f550d5df51d4272e33fc44
parent 9db7434a
......@@ -79,7 +79,7 @@ class FutureSplitter {
private:
std::shared_ptr<SharedPromise<T>> promise_;
Executor* e_ = nullptr;
Executor::KeepAlive<> e_;
static Executor* getExecutorFrom(Future<T>& f) {
// If the passed future had a null executor, use an inline executor
......
......@@ -15,6 +15,8 @@
*/
#include <folly/futures/FutureSplitter.h>
#include <folly/executors/ManualExecutor.h>
#include <folly/portability/GTest.h>
using namespace folly;
......@@ -174,3 +176,19 @@ TEST(FutureSplitter, splitFutureFailure) {
EXPECT_TRUE(f2.isReady());
EXPECT_TRUE(f2.hasException());
}
TEST(FutureSplitter, lifetime) {
struct ManualExecutorWithPriority : folly::ManualExecutor {
void addWithPriority(Func func, int8_t) override {
add(std::move(func));
}
};
ManualExecutorWithPriority ex;
auto ka = folly::ExecutorWithPriority::create(
folly::getKeepAliveToken(ex), folly::Executor::MID_PRI);
auto split = folly::splitFuture(folly::via(std::move(ka), [] { return 3; }));
ex.drain();
auto fut = split.getFuture().thenValue([](auto i) { return i + 1; });
ex.drain();
EXPECT_EQ(4, fut.value());
}
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