en:toolworks:docs:apparatus:operating

This is an old revision of the document!


Operating

The newer and more robust way of handle your chains is through the process called operating.

You can easily operate on your chain via a C++ lambda and this is how you do it:

Chain->Operate([](FMyTrait Trait)
{
    ...
});

Note that you’re not allowed to acquire a reference to the trait while processing a non-solid chain, only its copy. So in order to operate on a solid chain, you could do something like this:

SolidChain->Operate([](FMyTrait& Trait)
{
    ...
});

Now you can change the properties (fields) of the trait directly, without copying involved.

Solid Chains also support a special type of operating - a multi-threaded one. The function to call is explicitly named with a Concurrently prefix and accepts two more arguments: the maximum number of tasks to utilize and the minimum number of slots per each such task. For example:

SolidChain->OperateConcurrently([](FMyTrait& Trait)
{
    ...
}, 4, 32);

The second parameter helps to also limit the number of tasks. If there are too little slots available, excessive tasks not needed for that quantity won’t be queued at all.

One great thing about operating is that the function arguments are actually resolved and delivered automatically to your logic. For example, if you also modify the currently iterated subject, just specify the Subject handle in the very declaration of the routine:

Chain->Operate([](FSubjectHandle Subject, FMyTrait Trait)
{
    ...
});

This, of course, has to match the solidity of the chain. So for a solid chain this would be:

SolidChain->Operate([](FSolidSubjectHandle Subject, FMyTrait& Trait)
{
    ...
});

  • en/toolworks/docs/apparatus/operating.1639675891.txt.gz
  • Last modified: 2021/12/16 20:31
  • by vladius