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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
09e81b19ad
commit
82c06ac280
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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
|
||||
Reference in New Issue
Block a user