mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
74608417df
Summary: Changelog: [internal] If task that is being executed schedules a new task with higher priority, the new task will be dropped from the queue. To fix this, we always check if the top of the queue is what was executed and only then remove it. Example: Let's say there is task A with priority "normal". When we execute task A (which is not removed from the queue until later), it adds a task B with "immediate" priority. So priority queue now has two tasks: [1: B, 2: A] After task A finishes, inside workLoop, it will pop from top of the priority queue. But task A is no longer top of the priority queue (this is the bug) and it pops B. B is never executed and A is executed twice. Reviewed By: ShikaSD Differential Revision: D29841433 fbshipit-source-id: b2f1474fdfc7b3e2d42bae5b7f4ac7e6c3a37b54
47 lines
1.1 KiB
C++
47 lines
1.1 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 <better/optional.h>
|
|
#include <jsi/jsi.h>
|
|
#include <react/renderer/runtimescheduler/RuntimeSchedulerClock.h>
|
|
#include <react/renderer/runtimescheduler/SchedulerPriority.h>
|
|
|
|
namespace facebook::react {
|
|
|
|
class RuntimeScheduler;
|
|
class TaskPriorityComparer;
|
|
|
|
struct Task final {
|
|
Task(
|
|
SchedulerPriority priority,
|
|
jsi::Function callback,
|
|
std::chrono::steady_clock::time_point expirationTime);
|
|
|
|
private:
|
|
friend RuntimeScheduler;
|
|
friend TaskPriorityComparer;
|
|
|
|
SchedulerPriority priority;
|
|
better::optional<jsi::Function> callback;
|
|
RuntimeSchedulerClock::time_point expirationTime;
|
|
|
|
jsi::Value execute(jsi::Runtime &runtime);
|
|
};
|
|
|
|
class TaskPriorityComparer {
|
|
public:
|
|
inline bool operator()(
|
|
std::shared_ptr<Task> const &lhs,
|
|
std::shared_ptr<Task> const &rhs) {
|
|
return lhs->expirationTime > rhs->expirationTime;
|
|
}
|
|
};
|
|
|
|
} // namespace facebook::react
|