InstanceCreator::Options

Contents

InstanceCreator::Options#

inline InstanceCreator<Creator> &YR::internal::InstanceCreator::Options(InvokeOptions &&optsInput)#

Set options for the instance creation, including resource usage settings.

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

   YR::InvokeOptions opts;
   opts.cpu = 1000;
   opts.memory = 1000;
   auto ins = YR::Instance(SimpleCaculator::Constructor).Options(opts).Invoke();
   auto r3 = ins.Function(&SimpleCaculator::Plus).Invoke(1, 1);

   return 0;
}
Stateful functions specify local execution (nested stateless).
// Example: Setting options for instance creation
int incre(int x)
{
     return x + 1;
}

YR_INVOKE(incre)

struct Actor {
    int a;

    Actor() {}
    Actor(int init) { a = init; }
    static Actor *Create(int init) {
        return new Actor(init);
    }
    int InvokeIncre(bool local) {
        auto obj = YR::Function(incre).Options({ .alwaysLocalMode = local }).Invoke(a);
        return *YR::Get(obj);
    }
    MSGPACK_DEFINE(a)
};

YR_INVOKE(Actor::Create, &Actor::InvokeIncre)

void Forward(bool local)
{
    auto ins = YR::Instance(Actor::Create).Options({ .alwaysLocalMode = local }).Invoke(0);
    auto obj = ins.Function(&Actor::InvokeIncre).Invoke(true);
    std::cout << *YR::Get(obj) << std::endl;
    auto obj2 = ins.Function(&Actor::InvokeIncre).Invoke(false);
    std::cout << *YR::Get(obj2) << std::endl;
}

int main()
{
    Forward(true);
    Forward(false);
    return 0;
}

Note

This method does not take effect in local mode. It is designed for distributed scenarios where resource management and execution options are crucial.

Warning

This method is intended for distributed environments and does not function in local mode. Ensure that you are using it in the appropriate context where resource management and execution options are applicable.

Template Parameters:

Creator – The type of the worker function used to construct the instance.

Parameters:

optsInput – The options for the invocation, including resource usage and execution mode. For detailed descriptions, refer to the struct InvokeOptions.

Returns:

InstanceCreator<F> & A reference to the InstanceCreator object, allowing for a fluent interface to call the Invoke method directly.