Use folly::Function in folly::EventBase
Summary:[Folly] Use `folly::Function` in `folly::EventBase`. `folly::Function` is moveable but noncopyable and therefore supports wrapping moveable but noncopyable lambdas - like the kind that arises when move-capturing a `std::unique_ptr`. `std::function` is copyable - therefore it does not support wrapping such noncopyable lambdas. Switching `folly::EventBase` to use it will allow callers to pass such noncopyable lambdas, allowing, e.g.: ``` auto numptr = folly::make_unique<int>(7); // unique_ptr is noncopyable folly::EventBase eb; eb.runInLoop([numptr = std::move(numptr)] { // therefore lambda is noncopyable int num = *numptr; }); eb.loop(); ``` This allows us to move away from the `folly::MoveWrapper` hack, which worked like: ``` auto numptr = folly::make_unique<int>(7); // unique_ptr is noncopyable auto numptrw = folly::makeMoveWrapper(std::move(numptr)); // MoveWrapper is "copyable" - hacky folly::EventBase eb; eb.runInLoop([numptrw] { // therefore lambda is "copyable" - hacky int num = **numptrw; }); ``` We needed to do that hack while: But neither condition is true anymore. Reviewed By: spacedentist Differential Revision: D3143931 fb-gh-sync-id: 4fbdf5fb77eb5848ed1c6de942b022382141577f fbshipit-source-id: 4fbdf5fb77eb5848ed1c6de942b022382141577f
Showing
Please register or sign in to comment