InstanceFunctionHandler::Invoke

Contents

InstanceFunctionHandler::Invoke#

template<typename ...Args>
inline ObjectRef<ReturnType<F>> YR::InstanceFunctionHandler::Invoke(Args&&... args)#

Invokes a remote function by sending the request to a remote backend for execution.

This function sends a request to a remote backend to execute the specified function. The function’s arguments are serialized and transmitted to the backend, and the result is returned as an ObjectRef.

The function supports dependency resolution based on the argument types:

  1. If the function’s parameter is of type ArgType and the argument passed is of type ObjectRef<ArgType>, the request will only be sent after the corresponding computation for obj is completed, and the obj must be from the same client.

  2. If the function’s parameter is of type vector<ObjectRef<ArgType>> objs and the argument passed is of type vector<ObjectRef<ArgType>>, the request will only be sent after all computations corresponding to the objs are completed, and all ObjectRef instances must be from the same client.

  3. Arguments of other types do not support dependency resolution.

int main(void) {
    YR::Config conf;
    YR::Init(conf);

    auto ins = YR::Instance(SimpleCaculator::Constructor).Invoke();
    auto r3 = ins.Function(&SimpleCaculator::Plus).Invoke(1, 1);
    int res = *(YR::Get(r3));

    return 0;
}
In this example, the Invoke method is used to call the Plus function of the SimpleCaculator instance with arguments 1 and 1. The result is retrieved using YR::Get(r3).

Template Parameters:

Args – The types of the arguments passed to the function.

Parameters:

args – The arguments to be passed to the remote function. The types and number of arguments must match the function’s definition exactly. Ensure that the argument types match the expected types precisely to avoid issues caused by implicit type conversions.

Throws:

Exception – If the invocation fails, such as due to the function instance exiting abnormally or the user code executing abnormally.

Returns:

ObjectRef<ReturnType<F>>, A reference to the result object, which is essentially a key. To retrieve the actual value, use the YR::Get method.