From 02d2e85af36199c709158f5b1f77bb2bbbe7b3c9 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 8 Oct 2018 14:34:22 -0700 Subject: [PATCH] Fabric: `failCallback` implementation for MessageQueueEventBeat Summary: See comments in the code. Reviewed By: mdvacca Differential Revision: D10081502 fbshipit-source-id: b55bf019346a44c4b2980c70f547f53e4994e968 --- React/Fabric/Utils/MessageQueueEventBeat.mm | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/React/Fabric/Utils/MessageQueueEventBeat.mm b/React/Fabric/Utils/MessageQueueEventBeat.mm index c116755d8..49099f443 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 }); }