Skip to content

Commit 60471cb

Browse files
javachemeta-codesync[bot]
authored andcommitted
Remove unused microtask methods (#54435)
Summary: Pull Request resolved: #54435 We rely on the JS VM to provide a fully functional microtask queue, and this is no longer used. Changelog: [General][Breaking] Removed microtask API from JSTimerManager Reviewed By: mdvacca Differential Revision: D86420043 fbshipit-source-id: d8d08c4cbbb001504e533c4b730fdf95561c04a5
1 parent f8198f6 commit 60471cb

File tree

2 files changed

+0
-66
lines changed

2 files changed

+0
-66
lines changed

packages/react-native/ReactCommon/react/runtime/TimerManager.cpp

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "TimerManager.h"
99

1010
#include <cxxreact/TraceSection.h>
11-
#include <react/featureflags/ReactNativeFeatureFlags.h>
1211

1312
#include <cmath>
1413
#include <utility>
@@ -62,41 +61,6 @@ void TimerManager::setRuntimeExecutor(
6261
runtimeExecutor_ = std::move(runtimeExecutor);
6362
}
6463

65-
TimerHandle TimerManager::createReactNativeMicrotask(
66-
jsi::Function&& callback,
67-
std::vector<jsi::Value>&& args) {
68-
// Get the id for the callback.
69-
TimerHandle timerID = timerIndex_++;
70-
timers_.emplace(
71-
std::piecewise_construct,
72-
std::forward_as_tuple(timerID),
73-
std::forward_as_tuple(
74-
std::move(callback), std::move(args), /* repeat */ false));
75-
76-
reactNativeMicrotasksQueue_.push_back(timerID);
77-
return timerID;
78-
}
79-
80-
void TimerManager::callReactNativeMicrotasks(jsi::Runtime& runtime) {
81-
std::vector<TimerHandle> reactNativeMicrotasksQueue;
82-
while (!reactNativeMicrotasksQueue_.empty()) {
83-
reactNativeMicrotasksQueue.clear();
84-
reactNativeMicrotasksQueue.swap(reactNativeMicrotasksQueue_);
85-
86-
for (auto reactNativeMicrotaskID : reactNativeMicrotasksQueue) {
87-
// ReactNativeMicrotasks can clear other scheduled reactNativeMicrotasks.
88-
auto it = timers_.find(reactNativeMicrotaskID);
89-
if (it != timers_.end()) {
90-
it->second.invoke(runtime);
91-
92-
// Invoking a timer has the potential to delete it. Do not re-use the
93-
// existing iterator to erase it from the map.
94-
timers_.erase(reactNativeMicrotaskID);
95-
}
96-
}
97-
}
98-
}
99-
10064
TimerHandle TimerManager::createTimer(
10165
jsi::Function&& callback,
10266
std::vector<jsi::Value>&& args,
@@ -156,24 +120,6 @@ TimerHandle TimerManager::createRecurringTimer(
156120
return timerID;
157121
}
158122

159-
void TimerManager::deleteReactNativeMicrotask(
160-
jsi::Runtime& runtime,
161-
TimerHandle timerHandle) {
162-
if (timerHandle < 0) {
163-
throw jsi::JSError(
164-
runtime, "clearReactNativeMicrotask was called with an invalid handle");
165-
}
166-
167-
auto it = std::find(
168-
reactNativeMicrotasksQueue_.begin(),
169-
reactNativeMicrotasksQueue_.end(),
170-
timerHandle);
171-
if (it != reactNativeMicrotasksQueue_.end()) {
172-
reactNativeMicrotasksQueue_.erase(it);
173-
timers_.erase(timerHandle);
174-
}
175-
}
176-
177123
void TimerManager::deleteTimer(jsi::Runtime& runtime, TimerHandle timerHandle) {
178124
if (timerHandle < 0) {
179125
throw jsi::JSError(runtime, "clearTimeout called with an invalid handle");

packages/react-native/ReactCommon/react/runtime/TimerManager.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#pragma once
99

1010
#include <ReactCommon/RuntimeExecutor.h>
11-
#include <cstdint>
1211
#include <unordered_map>
1312
#include <vector>
1413

@@ -50,17 +49,11 @@ class TimerManager {
5049

5150
void setRuntimeExecutor(RuntimeExecutor runtimeExecutor) noexcept;
5251

53-
void callReactNativeMicrotasks(jsi::Runtime &runtime);
54-
5552
void callTimer(TimerHandle handle);
5653

5754
void attachGlobals(jsi::Runtime &runtime);
5855

5956
private:
60-
TimerHandle createReactNativeMicrotask(jsi::Function &&callback, std::vector<jsi::Value> &&args);
61-
62-
void deleteReactNativeMicrotask(jsi::Runtime &runtime, TimerHandle handle);
63-
6457
TimerHandle createTimer(
6558
jsi::Function &&callback,
6659
std::vector<jsi::Value> &&args,
@@ -88,11 +81,6 @@ class TimerManager {
8881
// As per WHATWG HTML 8.6.1 (Timers) ids must be greater than zero, i.e. start
8982
// at 1
9083
TimerHandle timerIndex_{1};
91-
92-
// The React Native microtask queue is used to back public APIs including
93-
// `queueMicrotask`, `clearImmediate`, and `setImmediate` (which is used by
94-
// the Promise polyfill) when the JSVM microtask mechanism is not used.
95-
std::vector<TimerHandle> reactNativeMicrotasksQueue_;
9684
};
9785

9886
} // namespace facebook::react

0 commit comments

Comments
 (0)