Use AnyInvocable in IomgrEngineClosure (#30352)

* use AnyInvocable in IomgrEngineClosure

* Automated change: Fix sanity tests

Co-authored-by: drfloob <drfloob@users.noreply.github.com>
pull/30356/head
AJ Heller 2 years ago committed by GitHub
parent a9c2f80a53
commit 462e6c1738
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      BUILD
  2. 11
      src/core/lib/event_engine/iomgr_engine/iomgr_engine_closure.h

@ -2312,6 +2312,7 @@ grpc_cc_library(
"src/core/lib/event_engine/iomgr_engine/iomgr_engine_closure.h",
],
external_deps = [
"absl/functional:any_invocable",
"absl/status",
"absl/utility",
],

@ -16,9 +16,9 @@
#define GRPC_CORE_LIB_EVENT_ENGINE_IOMGR_ENGINE_IOMGR_ENGINE_CLOSURE_H
#include <grpc/support/port_platform.h>
#include <functional>
#include <utility>
#include "absl/functional/any_invocable.h"
#include "absl/status/status.h"
#include "absl/utility/utility.h"
@ -35,7 +35,8 @@ class IomgrEngineClosure final
: public grpc_event_engine::experimental::EventEngine::Closure {
public:
IomgrEngineClosure() = default;
IomgrEngineClosure(std::function<void(absl::Status)>&& cb, bool is_permanent)
IomgrEngineClosure(absl::AnyInvocable<void(absl::Status)> cb,
bool is_permanent)
: cb_(std::move(cb)),
is_permanent_(is_permanent),
status_(absl::OkStatus()) {}
@ -51,19 +52,19 @@ class IomgrEngineClosure final
// This closure clean doesn't itself up after execution. It is expected to be
// cleaned up by the caller at the appropriate time.
static IomgrEngineClosure* ToPermanentClosure(
std::function<void(absl::Status)>&& cb) {
absl::AnyInvocable<void(absl::Status)> cb) {
return new IomgrEngineClosure(std::move(cb), true);
}
// This closure clean's itself up after execution. It is expected to be
// used only in tests.
static IomgrEngineClosure* TestOnlyToClosure(
std::function<void(absl::Status)>&& cb) {
absl::AnyInvocable<void(absl::Status)> cb) {
return new IomgrEngineClosure(std::move(cb), false);
}
private:
std::function<void(absl::Status)> cb_;
absl::AnyInvocable<void(absl::Status)> cb_;
bool is_permanent_ = false;
absl::Status status_;
};

Loading…
Cancel
Save