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:
If the function’s parameter is of type
ArgTypeand the argument passed is of typeObjectRef<ArgType>, the request will only be sent after the corresponding computation forobjis completed, and theobjmust be from the same client.If the function’s parameter is of type
vector<ObjectRef<ArgType>> objsand the argument passed is of typevector<ObjectRef<ArgType>>, the request will only be sent after all computations corresponding to theobjsare completed, and allObjectRefinstances must be from the same client.Arguments of other types do not support dependency resolution.
In this example, theint 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; }
Invokemethod is used to call thePlusfunction of theSimpleCaculatorinstance with arguments1and1. The result is retrieved usingYR::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::Getmethod.