From fa3525dc83b7d4f5ad224af2fa1cca2690c2e804 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 8 Oct 2018 14:34:20 -0700 Subject: [PATCH] Fabric: Introducting EventBeat::setFailCallback Summary: In some cases we have to have a way to notify a EventBeat consumer that the beat cannot be (and will not be) delivered, so we introducing special API for that. Reviewed By: mdvacca Differential Revision: D10081503 fbshipit-source-id: 4c5a392d32572f426e3744bdba797efcd29b8cb4 --- ReactCommon/fabric/events/EventBeat.cpp | 4 ++++ ReactCommon/fabric/events/EventBeat.h | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ReactCommon/fabric/events/EventBeat.cpp b/ReactCommon/fabric/events/EventBeat.cpp index 8dd62828b..48d175ec5 100644 --- a/ReactCommon/fabric/events/EventBeat.cpp +++ b/ReactCommon/fabric/events/EventBeat.cpp @@ -34,5 +34,9 @@ void EventBeat::setBeatCallback(const BeatCallback &beatCallback) { beatCallback_ = beatCallback; } +void EventBeat::setFailCallback(const FailCallback &failCallback) { + failCallback_ = failCallback; +} + } // namespace react } // namespace facebook diff --git a/ReactCommon/fabric/events/EventBeat.h b/ReactCommon/fabric/events/EventBeat.h index ef518eba5..14eababdd 100644 --- a/ReactCommon/fabric/events/EventBeat.h +++ b/ReactCommon/fabric/events/EventBeat.h @@ -24,6 +24,7 @@ public: virtual ~EventBeat() = default; using BeatCallback = std::function; + using FailCallback = std::function; /* * Communicates to the Beat that a consumer is waiting for the coming beat. @@ -44,11 +45,19 @@ public: virtual void induce() const; /* - * Sets a callback function. + * Sets the beat callback function. * The callback is must be called on the proper thread. */ void setBeatCallback(const BeatCallback &beatCallback); + /* + * Sets the fail callback function. + * Called in case if the beat cannot be performed anymore because of + * some external circumstances (e.g. execution thread is beling destructed). + * The callback can be called on any thread. + */ + void setFailCallback(const FailCallback &failCallback); + protected: /* * Should be used by sublasses to send a beat. @@ -57,6 +66,7 @@ protected: void beat() const; BeatCallback beatCallback_; + FailCallback failCallback_; mutable std::atomic isRequested_ {false}; };