Files
flipper/react-native/react-native-flipper/windows/ReactNativeFlipper/FlipperReactScheduler.h
Lorenzo Blasa 82c06ac280 React Scheduler
Summary: Introduces a Scheduler implementation using ReactDispatcher. The scheduler is/will be used by the FlipperConnectionManager as to serialise socket operations in it.

Reviewed By: antonk52

Differential Revision: D39053301

fbshipit-source-id: 5bc2d68a753ec4be3e28533b4c29e2d6ff6d8ba0
2022-09-04 08:02:21 -07:00

46 lines
1.1 KiB
C++

/*
* Copyright (c) Meta Platforms, Inc. and 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 <ReactDispatcher.h>
#include <winrt/Microsoft.ReactNative.h>
#include <thread>
#include "../../../../xplat/Flipper/FlipperScheduler.h"
using namespace winrt::Microsoft::ReactNative;
namespace facebook {
namespace flipper {
class FlipperReactScheduler : public Scheduler {
FlipperReactScheduler()
: dispatcher_(ReactDispatcher::CreateSerialDispatcher()) {}
virtual ~FlipperReactScheduler() {}
virtual void schedule(facebook::flipper::Func&& t) override {
dispatcher_.Post([t]() { t(); });
}
virtual void scheduleAfter(facebook::flipper::Func&& t, unsigned int ms)
override {
dispatcher_.Post([t, ms]() {
std::this_thread::sleep_for(std::chrono::microseconds(ms));
t();
});
}
virtual bool isRunningInOwnThread() override {
return true;
}
private:
ReactDispatcher dispatcher_;
};
} // namespace flipper
} // namespace facebook