diff --git a/cpp/include/ray/api.h b/cpp/include/ray/api.h index c366951af..f2aa0cf07 100644 --- a/cpp/include/ray/api.h +++ b/cpp/include/ray/api.h @@ -39,6 +39,14 @@ class Ray { template static ObjectRef 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 + static std::shared_ptr Get(const ObjectRef &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 - static std::shared_ptr Get(const ObjectRef &object); - template static TaskCaller TaskInternal(FuncType &func, ExecFuncType &exec_func, diff --git a/cpp/src/ray/test/api_test.cc b/cpp/src/ray/test/api_test.cc index 59de36ea7..f10b68a79 100644 --- a/cpp/src/ray/test/api_test.cc +++ b/cpp/src/ray/test/api_test.cc @@ -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();