From 7266ebda568aba15145110f39e91db207819f678 Mon Sep 17 00:00:00 2001 From: Emily Janzer Date: Wed, 24 Jul 2019 19:37:22 -0700 Subject: [PATCH] Move RuntimeExecutor declaration to react/utils Summary: Right now RuntimeExecutor is only used in Fabric. Moving it out of Fabric's uimanager/primitives.h and into react/utils so we can use it more broadly. Reviewed By: shergin Differential Revision: D16385366 fbshipit-source-id: 96063e536e1480bac078a9376fe55f7d8750477e --- React/Fabric/RCTSurfacePresenter.mm | 1 + React/Fabric/Utils/MainRunLoopEventBeat.h | 2 +- React/Fabric/Utils/RuntimeEventBeat.h | 2 +- .../react/fabric/jni/EventBeatManager.h | 2 +- ReactCommon/fabric/uimanager/Scheduler.h | 2 +- .../fabric/uimanager/SchedulerToolbox.h | 2 +- ReactCommon/fabric/uimanager/primitives.h | 3 --- ReactCommon/utils/BUCK | 1 + ReactCommon/utils/RuntimeExecutor.h | 25 +++++++++++++++++++ 9 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 ReactCommon/utils/RuntimeExecutor.h diff --git a/React/Fabric/RCTSurfacePresenter.mm b/React/Fabric/RCTSurfacePresenter.mm index 23b5ab18670..a5d15b87e88 100644 --- a/React/Fabric/RCTSurfacePresenter.mm +++ b/React/Fabric/RCTSurfacePresenter.mm @@ -34,6 +34,7 @@ #import #import #import +#import #import "MainRunLoopEventBeat.h" #import "RCTConversions.h" diff --git a/React/Fabric/Utils/MainRunLoopEventBeat.h b/React/Fabric/Utils/MainRunLoopEventBeat.h index b2878d9a198..8b78ffaa4fd 100644 --- a/React/Fabric/Utils/MainRunLoopEventBeat.h +++ b/React/Fabric/Utils/MainRunLoopEventBeat.h @@ -8,7 +8,7 @@ #include #include #include -#include +#include namespace facebook { namespace react { diff --git a/React/Fabric/Utils/RuntimeEventBeat.h b/React/Fabric/Utils/RuntimeEventBeat.h index 0fbecf47b80..67ba74fdb59 100644 --- a/React/Fabric/Utils/RuntimeEventBeat.h +++ b/React/Fabric/Utils/RuntimeEventBeat.h @@ -8,7 +8,7 @@ #include #include #include -#include +#include namespace facebook { namespace react { diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/EventBeatManager.h b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/EventBeatManager.h index 4fa39139a4d..3ef907ce432 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/EventBeatManager.h +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/EventBeatManager.h @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include diff --git a/ReactCommon/fabric/uimanager/Scheduler.h b/ReactCommon/fabric/uimanager/Scheduler.h index 163d3d945a5..199a7a61ea7 100644 --- a/ReactCommon/fabric/uimanager/Scheduler.h +++ b/ReactCommon/fabric/uimanager/Scheduler.h @@ -21,8 +21,8 @@ #include #include #include -#include #include +#include namespace facebook { namespace react { diff --git a/ReactCommon/fabric/uimanager/SchedulerToolbox.h b/ReactCommon/fabric/uimanager/SchedulerToolbox.h index 083609c6ad9..9505572229d 100644 --- a/ReactCommon/fabric/uimanager/SchedulerToolbox.h +++ b/ReactCommon/fabric/uimanager/SchedulerToolbox.h @@ -7,8 +7,8 @@ #include #include -#include #include +#include namespace facebook { namespace react { diff --git a/ReactCommon/fabric/uimanager/primitives.h b/ReactCommon/fabric/uimanager/primitives.h index 6d66f1620af..d7ac6f695f0 100644 --- a/ReactCommon/fabric/uimanager/primitives.h +++ b/ReactCommon/fabric/uimanager/primitives.h @@ -11,9 +11,6 @@ namespace facebook { namespace react { -using RuntimeExecutor = std::function &&callback)>; - struct EventHandlerWrapper : public EventHandler { EventHandlerWrapper(jsi::Function eventHandler) : callback(std::move(eventHandler)) {} diff --git a/ReactCommon/utils/BUCK b/ReactCommon/utils/BUCK index c582782dfa1..dc40820309b 100644 --- a/ReactCommon/utils/BUCK +++ b/ReactCommon/utils/BUCK @@ -30,6 +30,7 @@ rn_xplat_cxx_library( "fbsource//xplat/folly:headers_only", "fbsource//xplat/folly:memory", "fbsource//xplat/folly:molly", + "fbsource//xplat/jsi:jsi", react_native_xplat_target("better:better"), ], ) diff --git a/ReactCommon/utils/RuntimeExecutor.h b/ReactCommon/utils/RuntimeExecutor.h new file mode 100644 index 00000000000..a8f681390c4 --- /dev/null +++ b/ReactCommon/utils/RuntimeExecutor.h @@ -0,0 +1,25 @@ +// Copyright (c) Facebook, Inc. and its affiliates. + +// This source code is licensed under the MIT license found in the +// LICENSE file in the root directory of this source tree. + +#pragma once + +#include + +namespace facebook { +namespace react { + +/* + * Takes a function and calls it with a reference to a Runtime. The function + * will be called when it is safe to do so (i.e. it ensures non-concurrent + * access) and may be invoked asynchronously, depending on the implementation. + * If you need to access a Runtime, it's encouraged to use a RuntimeExecutor + * instead of storing a pointer to the Runtime itself, which makes it more + * difficult to ensure that the Runtime is being accessed safely. + */ +using RuntimeExecutor = + std::function &&callback)>; + +} // namespace react +} // namespace facebook