Summary:
[Folly] Remove `Executor::addPtr`.
It was there to support passing non-copyable callable objects wrapped as `std::shared_ptr`. It is no longer useful since we have `Function`, which is a non-copyable version of `std::function` which can support capturing non-copyable objects, and it is generally unused.
Reviewed By: spacedentist
Differential Revision:
D5983801
fbshipit-source-id:
b49a86f8dd7e5250a097b0e714a1bdf9ac362916
static const int8_t MID_PRI = 0;
static const int8_t HI_PRI = SCHAR_MAX;
- /// A convenience function for shared_ptr to legacy functors.
- ///
- /// Sometimes you have a functor that is move-only, and therefore can't be
- /// converted to a std::function (e.g. std::packaged_task). In that case,
- /// wrap it in a shared_ptr (or maybe folly::MoveWrapper) and use this.
- template <class P>
- void addPtr(P fn) {
- this->add([fn]() mutable { (*fn)(); });
- }
-
class KeepAlive {
public:
KeepAlive() {}
EXPECT_EQ(counter, 1);
}
-TEST(Executor, RunnablePtr) {
- InlineExecutor x;
- struct Runnable {
- std::function<void()> fn;
- void operator()() { fn(); }
- };
- size_t counter = 0;
- auto fnp = std::make_shared<Runnable>();
- fnp->fn = [&]{ counter++; };
- x.addPtr(fnp);
- EXPECT_EQ(counter, 1);
-}
-
TEST(Executor, ThrowableThen) {
InlineExecutor x;
auto f = Future<Unit>().then([]() { throw std::runtime_error("Faildog"); });