Skip to content

Commit dc9c5a7

Browse files
tsaichienfacebook-github-bot
authored andcommitted
Add IEventLoopControl APIs to hermes-interface
Summary: Adds `ISetEventLoopControl` to the Hermes-specific JSI. This interface specifies an user-defined, thread-safe function to schedule some task provided by the Hermes VM. The Hermes VM may use this function to "ask" the integrator to run some arbitrary task when the integrator has exclusive control of the runtime. Notably, this is useful for the Hermes implementation of Workers, where the Worker thread may ask the integrator to process an event. Differential Revision: D91905969
1 parent e0935e6 commit dc9c5a7

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

packages/react-native/ReactCommon/jsi/jsi/hermes-interfaces.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,34 @@ namespace debugger {
2626
class Debugger;
2727
}
2828

29+
#ifdef JSI_UNSTABLE
30+
struct IEventLoopControl {
31+
/// `scheduleCallback` is an integrator-provided function for the VM to
32+
/// schedule a callback task \p callback. This API must be thread-safe and run
33+
/// the callback when it is the exclusive user of the Runtime.
34+
virtual void scheduleCallback(const std::function<void()> callback) = 0;
35+
36+
protected:
37+
~IEventLoopControl() = default;
38+
};
39+
40+
struct JSI_EXPORT ISetEventLoopControl : public jsi::ICast {
41+
public:
42+
static constexpr jsi::UUID uuid{
43+
0x7b6902e6,
44+
0xfd38,
45+
0x11f0,
46+
0x8de9,
47+
0x0242ac120002};
48+
49+
/// Configures the eventloop control mechanism using \p eventLoopControl.
50+
virtual void setEventLoopControl(IEventLoopControl* eventLoopControl) = 0;
51+
52+
protected:
53+
~ISetEventLoopControl() = default;
54+
};
55+
#endif
56+
2957
/// Interface for Hermes-specific runtime methods.The actual implementations of
3058
/// the pure virtual methods are provided by Hermes API.
3159
class JSI_EXPORT IHermes : public jsi::ICast {

0 commit comments

Comments
 (0)