mirror of
https://github.com/status-im/react-native.git
synced 2025-02-22 14:18:23 +00:00
Fabric: Proper failCallback handling in EventBeatBasedExecutor
Summary: That's why we need the previous three diffs. Synchonous executor deadlocks if the beat is missing. Reviewed By: sahrens Differential Revision: D10081501 fbshipit-source-id: 9986d0a1844e642048b6f37a1fcb5f623a267663
This commit is contained in:
parent
02d2e85af3
commit
5f4aa6ae42
@ -46,6 +46,9 @@ void MessageQueueEventBeat::induce() const {
|
||||
// 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.
|
||||
// This trick is quite expensive due to deallocation and messing with atomic
|
||||
// counters. Seems we need this only for making hot-reloading mechanism
|
||||
// thread-safe. Hence, let's leave it to be DEBUG-only for now.
|
||||
auto wasExecuted = std::shared_ptr<bool>(new bool {false}, [this](bool *wasExecuted) {
|
||||
if (!*wasExecuted && failCallback_) {
|
||||
failCallback_();
|
||||
|
@ -19,7 +19,8 @@ using Mode = EventBeatBasedExecutor::Mode;
|
||||
EventBeatBasedExecutor::EventBeatBasedExecutor(std::unique_ptr<EventBeat> eventBeat):
|
||||
eventBeat_(std::move(eventBeat)) {
|
||||
|
||||
eventBeat_->setBeatCallback(std::bind(&EventBeatBasedExecutor::onBeat, this));
|
||||
eventBeat_->setBeatCallback(std::bind(&EventBeatBasedExecutor::onBeat, this, true));
|
||||
eventBeat_->setFailCallback(std::bind(&EventBeatBasedExecutor::onBeat, this, false));
|
||||
}
|
||||
|
||||
void EventBeatBasedExecutor::operator()(Routine routine, Mode mode) const {
|
||||
@ -52,7 +53,7 @@ void EventBeatBasedExecutor::execute(Task task) const {
|
||||
eventBeat_->induce();
|
||||
}
|
||||
|
||||
void EventBeatBasedExecutor::onBeat() const {
|
||||
void EventBeatBasedExecutor::onBeat(bool success) const {
|
||||
std::vector<Task> tasks;
|
||||
|
||||
{
|
||||
@ -67,7 +68,9 @@ void EventBeatBasedExecutor::onBeat() const {
|
||||
}
|
||||
|
||||
for (const auto task : tasks) {
|
||||
task.routine();
|
||||
if (success) {
|
||||
task.routine();
|
||||
}
|
||||
|
||||
if (task.callback) {
|
||||
task.callback();
|
||||
|
@ -43,7 +43,7 @@ public:
|
||||
void operator()(Routine routine, Mode mode = Mode::Asynchronous) const;
|
||||
|
||||
private:
|
||||
void onBeat() const;
|
||||
void onBeat(bool success = true) const;
|
||||
void execute(Task task) const;
|
||||
|
||||
std::unique_ptr<EventBeat> eventBeat_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user