mirror of
https://github.com/status-im/react-native.git
synced 2025-01-27 09:45:04 +00:00
57bbce9bd9
Summary: @public EventBeat is an abstraction around proper event scheduling combining proper timing and proper threading. Event Queues use Event Beat to ensure that events are delivered on proper threads and in proper timing (probably batched). Consumers can `request` the next beat and `induce` immediatly beat. MainRunLoopEventBeat implements particular Event Beat synchronized with the main event loop and calling a callback on the main thread. Reviewed By: mdvacca Differential Revision: D8886229 fbshipit-source-id: 1a42fcbf4cd61c6cb4c502890566c98b00226f31
40 lines
698 B
C++
40 lines
698 B
C++
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#include "EventBeat.h"
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
void EventBeat::request() const {
|
|
isRequested_ = true;
|
|
}
|
|
|
|
void EventBeat::beat() const {
|
|
if (!this->isRequested_) {
|
|
return;
|
|
}
|
|
|
|
if (!beatCallback_) {
|
|
return;
|
|
}
|
|
|
|
beatCallback_();
|
|
isRequested_ = false;
|
|
}
|
|
|
|
void EventBeat::induce() const {
|
|
// Default implementation does nothing.
|
|
}
|
|
|
|
void EventBeat::setBeatCallback(const BeatCallback &beatCallback) {
|
|
beatCallback_ = beatCallback;
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|