diff --git a/React/Fabric/Utils/MessageQueueEventBeat.mm b/React/Fabric/Utils/MessageQueueEventBeat.mm index c116755d88d..49099f443b9 100644 --- a/React/Fabric/Utils/MessageQueueEventBeat.mm +++ b/React/Fabric/Utils/MessageQueueEventBeat.mm @@ -41,10 +41,26 @@ void MessageQueueEventBeat::induce() const { return; } +#ifndef NDEBUG + // We do a trick here. + // If `wasExecuted` was destroyed before set to `true`, + // it means that the execution block was deallocated not being executed. + // This indicates that `messageQueueThread_` is being deallocated. + auto wasExecuted = std::shared_ptr(new bool {false}, [this](bool *wasExecuted) { + if (!*wasExecuted && failCallback_) { + failCallback_(); + } + delete wasExecuted; + }); +#endif + isBusy_ = true; - messageQueueThread_->runOnQueue([this]() { + messageQueueThread_->runOnQueue([=]() mutable { this->beat(); isBusy_ = false; +#ifndef NDEBUG + *wasExecuted = true; +#endif }); }