Skip to content

Commit

Permalink
Add return value to RuntimeScheduler unstable_scheduleCallback
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Apr 13, 2021
1 parent 2779129 commit 3c14c19
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "RuntimeSchedulerBinding.h"
#include "SchedulerPriority.h"
#include "primitives.h"

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

// TODO: return reference to the task.
return jsi::Value::undefined();
return valueFromTask(runtime, task);
});
}

Expand Down
29 changes: 29 additions & 0 deletions ReactCommon/react/renderer/runtimescheduler/primitives.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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 <folly/dynamic.h>
#include <jsi/jsi.h>
#include <react/renderer/runtimescheduler/Task.h>

namespace facebook::react {

struct TaskWrapper : public jsi::HostObject {
TaskWrapper(std::shared_ptr<Task> const &task) : task(task) {}

std::shared_ptr<Task> task;
};

inline static jsi::Value valueFromTask(
jsi::Runtime &runtime,
std::shared_ptr<Task> const &task) {
return jsi::Object::createFromHostObject(
runtime, std::make_shared<TaskWrapper>(task));
}

} // namespace facebook::react

0 comments on commit 3c14c19

Please sign in to comment.