Get#

Retrieve the value of an object from the backend storage based on its key. The interface call will block until the object’s value is retrieved or a timeout occurs.

template<typename T>
std::shared_ptr<T> YR::Get(const ObjectRef<T> &obj, int timeout = DEFAULT_GET_TIMEOUT_SEC)#

Get the value of an ObjectRef.

Get the value of the object stored in the backend storage according to the key of the object. The interface call will block until the value of the object is obtained or the timeout occurs.

auto objRef = YR::Put(100);
auto value = *(YR::Get(objRef));
assert(value == 100);  // should be 100

Template Parameters:

T – the type of the object, Must not be void.

Parameters:
  • obj – the obj’s ObjectRef.

  • timeout – the timeout.

Throws:

Exception – if the object doesn’t exist or timeout.

Returns:

the shared pointer of the real value.

template<typename T>
std::vector<std::shared_ptr<T>> YR::Get(const std::vector<ObjectRef<T>> &objs, int timeout = DEFAULT_GET_TIMEOUT_SEC, bool allowPartial = false)#

Get the value of an ObjectRef.

int originValue = 100;
auto objRefs = std::vector<YR::ObjectRef<int>>{YR::Put(100), YR::Put(101)};
auto values = *(YR::Get(objRefs));
assert(values.size() == 2);  // should be [100, 101]
assert(*values[0] == 100);
assert(*values[1] == 101);

Template Parameters:

T – the type of the object, Must not be void.

Parameters:
  • objs – the objs’ ObjectRef as a vector, should less than 10000.

  • timeout – the timeout.Default to 300.

  • allowPartial – if set to true, partialially ok will not throw an error.

Throws:

Exception – if the all object don’t exist or timeout and not allowPartial.

Returns:

the shared pointers of the real values.

const int YR::DEFAULT_GET_TIMEOUT_SEC = 300#