@@ -43,7 +43,7 @@ class RuntimeSchedulerTest : public testing::Test {
43
43
}
44
44
45
45
jsi::Function createHostFunctionFromLambda (
46
- std::function<void (bool )> callback) {
46
+ std::function<jsi::Value (bool )> callback) {
47
47
return jsi::Function::createFromHostFunction (
48
48
*runtime_,
49
49
jsi::PropNameID::forUtf8 (*runtime_, " " ),
@@ -55,8 +55,7 @@ class RuntimeSchedulerTest : public testing::Test {
55
55
size_t ) noexcept -> jsi::Value {
56
56
++hostFunctionCallCount_;
57
57
auto didUserCallbackTimeout = arguments[0 ].getBool ();
58
- callback (didUserCallbackTimeout);
59
- return jsi::Value::undefined ();
58
+ return callback (didUserCallbackTimeout);
60
59
});
61
60
}
62
61
@@ -93,6 +92,7 @@ TEST_F(RuntimeSchedulerTest, scheduleSingleTask) {
93
92
createHostFunctionFromLambda ([&didRunTask](bool didUserCallbackTimeout) {
94
93
didRunTask = true ;
95
94
EXPECT_FALSE (didUserCallbackTimeout);
95
+ return jsi::Value::undefined ();
96
96
});
97
97
98
98
runtimeScheduler_->scheduleTask (
@@ -113,6 +113,7 @@ TEST_F(RuntimeSchedulerTest, scheduleImmediatePriorityTask) {
113
113
createHostFunctionFromLambda ([&didRunTask](bool didUserCallbackTimeout) {
114
114
didRunTask = true ;
115
115
EXPECT_FALSE (didUserCallbackTimeout);
116
+ return jsi::Value::undefined ();
116
117
});
117
118
118
119
runtimeScheduler_->scheduleTask (
@@ -135,6 +136,7 @@ TEST_F(RuntimeSchedulerTest, taskExpiration) {
135
136
// Task has timed out but the parameter is deprecated and `false` is
136
137
// hardcoded.
137
138
EXPECT_FALSE (didUserCallbackTimeout);
139
+ return jsi::Value::undefined ();
138
140
});
139
141
140
142
runtimeScheduler_->scheduleTask (
@@ -157,6 +159,7 @@ TEST_F(RuntimeSchedulerTest, scheduleTwoTasksWithSamePriority) {
157
159
auto callbackOne =
158
160
createHostFunctionFromLambda ([this , &firstTaskCallOrder](bool ) {
159
161
firstTaskCallOrder = hostFunctionCallCount_;
162
+ return jsi::Value::undefined ();
160
163
});
161
164
162
165
runtimeScheduler_->scheduleTask (
@@ -166,6 +169,7 @@ TEST_F(RuntimeSchedulerTest, scheduleTwoTasksWithSamePriority) {
166
169
auto callbackTwo =
167
170
createHostFunctionFromLambda ([this , &secondTaskCallOrder](bool ) {
168
171
secondTaskCallOrder = hostFunctionCallCount_;
172
+ return jsi::Value::undefined ();
169
173
});
170
174
171
175
runtimeScheduler_->scheduleTask (
@@ -188,6 +192,7 @@ TEST_F(RuntimeSchedulerTest, scheduleTwoTasksWithDifferentPriorities) {
188
192
auto callbackOne =
189
193
createHostFunctionFromLambda ([this , &lowPriorityTaskCallOrder](bool ) {
190
194
lowPriorityTaskCallOrder = hostFunctionCallCount_;
195
+ return jsi::Value::undefined ();
191
196
});
192
197
193
198
runtimeScheduler_->scheduleTask (
@@ -197,6 +202,7 @@ TEST_F(RuntimeSchedulerTest, scheduleTwoTasksWithDifferentPriorities) {
197
202
auto callbackTwo = createHostFunctionFromLambda (
198
203
[this , &userBlockingPriorityTaskCallOrder](bool ) {
199
204
userBlockingPriorityTaskCallOrder = hostFunctionCallCount_;
205
+ return jsi::Value::undefined ();
200
206
});
201
207
202
208
runtimeScheduler_->scheduleTask (
@@ -216,8 +222,10 @@ TEST_F(RuntimeSchedulerTest, scheduleTwoTasksWithDifferentPriorities) {
216
222
217
223
TEST_F (RuntimeSchedulerTest, cancelTask) {
218
224
bool didRunTask = false ;
219
- auto callback =
220
- createHostFunctionFromLambda ([&didRunTask](bool ) { didRunTask = true ; });
225
+ auto callback = createHostFunctionFromLambda ([&didRunTask](bool ) {
226
+ didRunTask = true ;
227
+ return jsi::Value::undefined ();
228
+ });
221
229
222
230
auto task = runtimeScheduler_->scheduleTask (
223
231
SchedulerPriority::NormalPriority, std::move (callback));
@@ -233,4 +241,36 @@ TEST_F(RuntimeSchedulerTest, cancelTask) {
233
241
EXPECT_EQ (stubQueue_->size (), 0 );
234
242
}
235
243
244
+ TEST_F (RuntimeSchedulerTest, continuationTask) {
245
+ bool didRunTask = false ;
246
+ bool didContinuationTask = false ;
247
+
248
+ auto callback = createHostFunctionFromLambda ([&](bool ) {
249
+ didRunTask = true ;
250
+ return jsi::Function::createFromHostFunction (
251
+ *runtime_,
252
+ jsi::PropNameID::forUtf8 (*runtime_, " " ),
253
+ 1 ,
254
+ [&](jsi::Runtime &runtime,
255
+ jsi::Value const &,
256
+ jsi::Value const *arguments,
257
+ size_t ) noexcept -> jsi::Value {
258
+ didContinuationTask = true ;
259
+ return jsi::Value::undefined ();
260
+ });
261
+ });
262
+
263
+ auto task = runtimeScheduler_->scheduleTask (
264
+ SchedulerPriority::NormalPriority, std::move (callback));
265
+
266
+ EXPECT_FALSE (didRunTask);
267
+ EXPECT_EQ (stubQueue_->size (), 1 );
268
+
269
+ stubQueue_->tick ();
270
+
271
+ EXPECT_TRUE (didRunTask);
272
+ EXPECT_TRUE (didContinuationTask);
273
+ EXPECT_EQ (stubQueue_->size (), 0 );
274
+ }
275
+
236
276
} // namespace facebook::react
0 commit comments