mirror of
https://github.com/status-im/react-native.git
synced 2025-02-23 22:58:19 +00:00
Summary: We double down on JSI in Fabric. So, practically, JSI is now a hard dependency for Fabric. I hope it's for good. Now `jsi::Runtime` is coupled with scheduling via `EventExecuter`, so we have to make `jsi::Runtime` a part of `EventBeat` to proxy runtime reference to bindgings. Reviewed By: sahrens Differential Revision: D12837225 fbshipit-source-id: 98edc33d6a3358e6c2905f2f03ce0004a9ca0503
77 lines
2.2 KiB
C++
77 lines
2.2 KiB
C++
/**
|
|
* 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 <jsi/jsi.h>
|
|
#include <atomic>
|
|
#include <functional>
|
|
#include <memory>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
/*
|
|
* Event Beat serves two interleaving purposes: synchronization of event queues
|
|
* and ensuring that event dispatching happens on propper threads.
|
|
*/
|
|
class EventBeat {
|
|
public:
|
|
virtual ~EventBeat() = default;
|
|
|
|
using BeatCallback = std::function<void(jsi::Runtime &runtime)>;
|
|
using FailCallback = std::function<void()>;
|
|
|
|
/*
|
|
* Communicates to the Beat that a consumer is waiting for the coming beat.
|
|
* A consumer must request coming beat after the previous beat happened
|
|
* to receive a next coming one.
|
|
*/
|
|
virtual void request() const;
|
|
|
|
/*
|
|
* Induces the next beat to happen as soon as possible. If the method
|
|
* is called on the proper thread, the beat must happen synchronously.
|
|
* Subclasses might override this method to implement specific
|
|
* out-of-turn beat scheduling.
|
|
* Some types of Event Beats do not support inducing, hence the default
|
|
* implementation does nothing.
|
|
* Receiver might ignore the call if a beat was not requested.
|
|
*/
|
|
virtual void induce() const;
|
|
|
|
/*
|
|
* Sets the beat callback function.
|
|
* The callback is must be called on the proper thread.
|
|
*/
|
|
void setBeatCallback(const BeatCallback &beatCallback);
|
|
|
|
/*
|
|
* Sets the fail callback function.
|
|
* Called in case if the beat cannot be performed anymore because of
|
|
* some external circumstances (e.g. execution thread is beling destructed).
|
|
* The callback can be called on any thread.
|
|
*/
|
|
void setFailCallback(const FailCallback &failCallback);
|
|
|
|
protected:
|
|
/*
|
|
* Should be used by sublasses to send a beat.
|
|
* Receiver might ignore the call if a beat was not requested.
|
|
*/
|
|
void beat(jsi::Runtime &runtime) const;
|
|
|
|
BeatCallback beatCallback_;
|
|
FailCallback failCallback_;
|
|
mutable std::atomic<bool> isRequested_{false};
|
|
};
|
|
|
|
using EventBeatFactory = std::function<std::unique_ptr<EventBeat>()>;
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|