Skip to content

Commit 3c14c19

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
Add return value to RuntimeScheduler unstable_scheduleCallback
Summary: Changelog: [internal] unstable_scheduleCallback needs to return reference to the created task so it can be cancelled later. Reviewed By: mdvacca Differential Revision: D27622779 fbshipit-source-id: 54160015c7f98e123d08c2e13efac4f498d3ba5e
1 parent 2779129 commit 3c14c19

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

ReactCommon/react/renderer/runtimescheduler/RuntimeSchedulerBinding.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "RuntimeSchedulerBinding.h"
99
#include "SchedulerPriority.h"
10+
#include "primitives.h"
1011

1112
#include <react/debug/react_native_assert.h>
1213
#include <memory>
@@ -65,8 +66,7 @@ jsi::Value RuntimeSchedulerBinding::get(
6566
auto task = std::make_shared<Task>(priority, std::move(callback));
6667
runtimeScheduler_.scheduleTask(task);
6768

68-
// TODO: return reference to the task.
69-
return jsi::Value::undefined();
69+
return valueFromTask(runtime, task);
7070
});
7171
}
7272

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#include <folly/dynamic.h>
11+
#include <jsi/jsi.h>
12+
#include <react/renderer/runtimescheduler/Task.h>
13+
14+
namespace facebook::react {
15+
16+
struct TaskWrapper : public jsi::HostObject {
17+
TaskWrapper(std::shared_ptr<Task> const &task) : task(task) {}
18+
19+
std::shared_ptr<Task> task;
20+
};
21+
22+
inline static jsi::Value valueFromTask(
23+
jsi::Runtime &runtime,
24+
std::shared_ptr<Task> const &task) {
25+
return jsi::Object::createFromHostObject(
26+
runtime, std::make_shared<TaskWrapper>(task));
27+
}
28+
29+
} // namespace facebook::react

0 commit comments

Comments
 (0)