Fabric: Using EventBeat::Owner to prevent a crash caused by issuing a bit for already deallocated Scheduler

Summary:
The concept of `EventBeat::Owner` was introduced in D17128549, this diff implements some missing pieces of that.

After the change, AsyncEventEmitter will check the existence of the "owner" (which is EventDispatcher) which guarantees that the rest of the pipeline is still alive (the validity of Runtime is guaranteed by RuntimeExecutor separately).

The overall workflow is described in D17128549.

Reviewed By: JoshuaGross

Differential Revision: D17410738

fbshipit-source-id: a1ae8e09600546874cdc7c622b3d884b71c5b48d
This commit is contained in:
Valentin Shergin
2019-09-17 16:44:58 -07:00
committed by Facebook Github Bot
parent e98a4b5eff
commit 46120bc38a
@@ -41,7 +41,12 @@ class AsyncEventBeat : public EventBeat {
}
void induce() const override {
runtimeExecutor_([=](jsi::Runtime &runtime) {
runtimeExecutor_([this, ownerBox = ownerBox_](jsi::Runtime &runtime) {
auto owner = ownerBox->owner.lock();
if (!owner) {
return;
}
this->beat(runtime);
});
}