Add runtime scheduler priorities

Summary:
Changelog: [internal]

Add runtime scheduler priorities

Reviewed By: JoshuaGross

Differential Revision: D27618305

fbshipit-source-id: 95e4e02f3473acb41bca0c22df7b271a8d710f34
This commit is contained in:
Samuel Susla
2021-04-13 01:55:03 -07:00
committed by Facebook GitHub Bot
parent 1b0683533a
commit 8d5c22edfd
2 changed files with 50 additions and 2 deletions
@@ -6,6 +6,7 @@
*/
#include "RuntimeSchedulerBinding.h"
#include "SchedulerPriority.h"
#include <memory>
@@ -37,8 +38,29 @@ RuntimeSchedulerBinding::createAndInstallIfNeeded(jsi::Runtime &runtime) {
jsi::Value RuntimeSchedulerBinding::get(
jsi::Runtime &runtime,
jsi::PropNameID const &name) {
(void)runtime;
(void)name;
auto propertyName = name.utf8(runtime);
if (propertyName == "unstable_ImmediatePriority") {
return jsi::Value(runtime, serialize(SchedulerPriority::ImmediatePriority));
}
if (propertyName == "unstable_UserBlockingPriority") {
return jsi::Value(
runtime, serialize(SchedulerPriority::UserBlockingPriority));
}
if (propertyName == "unstable_NormalPriority") {
return jsi::Value(runtime, serialize(SchedulerPriority::NormalPriority));
}
if (propertyName == "unstable_LowPriority") {
return jsi::Value(runtime, serialize(SchedulerPriority::LowPriority));
}
if (propertyName == "unstable_IdlePriority") {
return jsi::Value(runtime, serialize(SchedulerPriority::IdlePriority));
}
return jsi::Value::undefined();
}
@@ -0,0 +1,26 @@
/*
* 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
namespace facebook::react {
enum class SchedulerPriority : int {
ImmediatePriority = 1,
UserBlockingPriority = 2,
NormalPriority = 3,
LowPriority = 4,
IdlePriority = 5,
};
static constexpr std::underlying_type<SchedulerPriority>::type serialize(
SchedulerPriority schedulerPriority) {
return static_cast<std::underlying_type<SchedulerPriority>::type>(
schedulerPriority);
}
} // namespace facebook::react