mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
08ef1df1ba
Summary: Changelog: [internal] Implement RuntimeScheduler::cancelTask and expose it through JSI. JavaScript implementation: https://github.com/facebook/react/blob/master/packages/scheduler/src/forks/SchedulerNoDOM.js#L384-L397 Reviewed By: mdvacca Differential Revision: D27648071 fbshipit-source-id: 91ae92b336017596fb658831824e971c7e047cd2
34 lines
890 B
C++
34 lines
890 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)
|
|
: priority_(priority), callback_(std::move(callback)) {}
|
|
|
|
SchedulerPriority Task::getPriority() const {
|
|
return priority_;
|
|
}
|
|
|
|
void Task::cancel() {
|
|
// Null out the callback to indicate the task has been canceled. (Can't
|
|
// remove from the priority_queue because you can't remove arbitrary nodes
|
|
// from an array based heap, only the first one.)
|
|
callback_.reset();
|
|
}
|
|
|
|
void Task::operator()(jsi::Runtime &runtime) const {
|
|
if (callback_) {
|
|
// Cancelled task doesn't have a callback.
|
|
callback_.value().call(runtime, {});
|
|
}
|
|
}
|
|
|
|
} // namespace facebook::react
|