Files
react-native/ReactCommon/react/renderer/runtimescheduler/Task.cpp
T
Samuel Susla a8d0dd6646 Implement task continuation
Summary:
Changelog: [internal]

Scheduler's callback have option to add more work inside callback. This work stays on top of the priority queue and gives React ability to flush all work synchronously if need.

This diff adds use of `shouldYield_` to the workLoop. For now, it always evaluates to false. In the future when we allow access to the scheduler to native, it will allow yielding.

Relevant code in JavaScript:
https://github.com/facebook/react/blob/master/packages/scheduler/src/forks/SchedulerNoDOM.js#L190

Reviewed By: mdvacca

Differential Revision: D27823528

fbshipit-source-id: 016101e41eb7c41c2ac5abb55f803814867b8517
2021-04-20 09:22:23 -07:00

32 lines
887 B
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.
*/
#include "RuntimeScheduler.h"
namespace facebook::react {
Task::Task(
SchedulerPriority priority,
jsi::Function callback,
std::chrono::steady_clock::time_point expirationTime)
: priority(priority),
callback(std::move(callback)),
expirationTime(expirationTime) {}
jsi::Value Task::execute(jsi::Runtime &runtime) const {
// Cancelled task doesn't have a callback.
if (callback) {
// Callback in JavaScript is expecting a single bool parameter.
// React team plans to remove it and it is safe to pass in
// hardcoded false value.
return callback.value().call(runtime, {false});
}
return jsi::Value::undefined();
}
} // namespace facebook::react