diff --git a/packages/react-native/ReactCommon/react/renderer/core/EventBeat.h b/packages/react-native/ReactCommon/react/renderer/core/EventBeat.h index c67b341d452a7b..79a36fb70b1c97 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/EventBeat.h +++ b/packages/react-native/ReactCommon/react/renderer/core/EventBeat.h @@ -20,27 +20,33 @@ namespace facebook::react { /* * Event Beat serves two interleaving purposes: synchronization of event queues * and ensuring that event dispatching happens on proper threads. + * + * EventBeat is meant to be subclassed by platform-specific implementations. + * The platform-specific implementation must call EventBeat::induce(). The + * appropriate time to call induce is when the host platform events were queued + * in the EventQueue for a given UI frame. For example, on iOS, + * EventBeat::induce() is called before the main run loop goes to sleep. On + * Android, EventBeat::induce() is called from Android's Choreographer. */ class EventBeat { public: /* * The concept of `Owner` * The purpose of `EventBeat` is handling an asynchronous callback to itself - * which is being delivered on some different thread. That brings a challenge + * which is being delivered on a different thread. That brings a challenge * of ensuring that the `EventBeat` object stays valid during the timeframe of * callback execution. The concept of Owner helps with that. The owner is a * shared pointer that retains (probably indirectly) the `EventBeat` object. * To ensure the correctness of the call, `EventBeat` retains the owner - * (practically creating a retain cycle) during executing the callback. In - * case if the pointer to the owner already null, `EventBeat` skips executing - * the callback. It's impossible to retain itself directly or refer to the - * shared pointer to itself from a constructor. `OwnerBox` is designed to work - * around this issue; it allows to store the pointer later, right after the - * creation of some other object that owns an `EventBeat`. + * weakly during executing the callback. In case if the pointer to the owner + * already null, `EventBeat` skips executing the callback. It's impossible to + * retain itself directly or refer to the shared pointer to itself from a + * constructor. `OwnerBox` is designed to work around this issue; it allows to + * store the pointer later, right after the creation of some other object that + * owns an `EventBeat`. */ - using Owner = std::weak_ptr; struct OwnerBox { - Owner owner; + std::weak_ptr owner; }; using Factory = std::function(