[cpp worker] support Ray::Get() static method (#9809)

This commit is contained in:
SongGuyang
2020-08-06 16:20:05 +08:00
committed by GitHub
parent 7d4f204aa8
commit 17ddcd8691
2 changed files with 21 additions and 4 deletions
+8 -4
View File
@@ -39,6 +39,14 @@ class Ray {
template <typename T>
static ObjectRef<T> Put(const T &obj);
/// Get a single object from the object store.
/// This method will be blocked until the object is ready.
///
/// \param[in] object The object reference which should be returned.
/// \return shared pointer of the result.
template <typename T>
static std::shared_ptr<T> Get(const ObjectRef<T> &object);
/// Get a list of objects from the object store.
/// This method will be blocked until all the objects are ready.
///
@@ -77,10 +85,6 @@ class Ray {
static std::once_flag is_inited_;
/// Used by ObjectRef to implement .Get()
template <typename T>
static std::shared_ptr<T> Get(const ObjectRef<T> &object);
template <typename ReturnType, typename FuncType, typename ExecFuncType,
typename... ArgTypes>
static TaskCaller<ReturnType> TaskInternal(FuncType &func, ExecFuncType &exec_func,
+13
View File
@@ -42,6 +42,19 @@ TEST(RayApiTest, PutTest) {
EXPECT_EQ(1, *i1);
}
TEST(RayApiTest, StaticGetTest) {
Ray::Init();
/// `Get` member function
auto obj_ref1 = Ray::Put(100);
auto res1 = obj_ref1.Get();
EXPECT_EQ(100, *res1);
/// `Get` static function
auto obj_ref2 = Ray::Put(200);
auto res2 = Ray::Get(obj_ref2);
EXPECT_EQ(200, *res2);
}
TEST(RayApiTest, WaitTest) {
Ray::Init();
auto r0 = Ray::Task(Return1).Remote();