Wait

Wait#

template<typename T>
using YR::WaitResult = std::pair<std::vector<ObjectRef<T>>, std::vector<ObjectRef<T>>>#

Represents a pair of vector<ObjectRef>, where the former represents completed ObjectRef and the latter represents pending ObjectRef.

Template Parameters:

T – The type of the objects being waited for.

template<typename T>
void YR::Wait(const ObjectRef<T> &obj, int timeoutSec = -1)#

Waits for the value of an object in the data system to be ready based on the object’s key.

int timeout = 30;
auto obj = YR::Function(Handler).Invoke(1);
YR::Wait(obj, timeout);

Template Parameters:

T – The type of the object to wait for.

Parameters:
  • obj – A reference to the object in the data system.

  • timeoutSec – Timeout limit in milliseconds. -1 indicates no time limit.

template<typename T>
WaitResult<T> YR::Wait(const std::vector<ObjectRef<T>> &objs, std::size_t waitNum, int timeoutSec = -1)#

Waits for the values of a set of objects in the data system to be ready based on their keys.

When waiting for a group of ObjectRef, you can specify to wait for at least waitNum objects to be calculated.

int num = 5;
std::size_t waitNum = 1;
std::vector<YR::ObjectRef<int>> vec;
for (int i = 0; i < num; ++i) {
    auto obj = YR::Function(Handler).Invoke(i);
    vec.emplace_back(std::move(obj));
}
int timeout = 30;
auto waitResult = YR::Wait(vec, waitNum, timeout);
std::cout << waitResult.first.size() << std::endl;
std::cout << waitResult.second.size() << std::endl;

Template Parameters:

T – The type of the objects to wait for.

Parameters:
  • objs – A collection of object references in the data system.

  • waitNum – The minimum number of ObjectRef to wait for.

  • timeoutSec – Timeout limit in milliseconds. -1 indicates no time limit.

Returns:

A pair of vector<ObjectRef>, where the first vector contains completed ObjectRef and the second contains pending ObjectRef. The following invariant always holds:

  1. waitNum <= waitResult.first.size() <= objs.size()

  2. waitResult.first.size() + waitResult.second.size() == objs.size()