Na ovoj stranici

Tasking::Group Class

class Tasking::Group

Grupa predstavlja osnovni element za sastavljanje deklarativnih recepata koji opisuju kako izvršiti i upravljati ugniježđenim stablom asinkronih zadataka. Više...

Header: #include <solutions/tasking/tasktree.h>
Inherits: Tasking::ExecutableItem

Napomena: Sve funkcije u ovoj klasi su reentrantne.

Javne funkcije

Group(const Tasking::GroupItems &children)
Group(std::initializer_list<Tasking::GroupItem> children)

Detaljan opis

Grupa je spremnik za ostale stavke grupe. Obuhvaća podređene zadatke u jednu cjelinu, koja se od strane nadređene grupe doživljava kao jedan asinhroni zadatak. Budući da je Grupa tipa GroupItem, može biti i podređena drugoj grupi.

Umetnite podređene zadatke u grupu koristeći aliasirane prilagođene nazive zadataka, kao što su ConcurrentCallTask<ResultType> ili NetworkQueryTask:

const Group group {
    NetworkQueryTask(...),
    ConcurrentCallTask<int>(...)
};

Ponašanje grupe može se prilagoditi umetanjem stavki koje vraćaju funkcije parallelLimit() ili workflowPolicy():

const Group group {
    parallel,
    continueOnError,
    NetworkQueryTask(...),
    NetworkQueryTask(...)
};

Grupa može sadržavati ugniježđene grupe:

const Group group {
    finishAllAndSuccess,
    NetworkQueryTask(...),
    Group {
        NetworkQueryTask(...),
        Group {
            parallel,
            NetworkQueryTask(...),
            NetworkQueryTask(...),
        }
        ConcurrentCallTask<QString>(...)
    }
};

Grupa može dinamički instancirati prilagođenu strukturu pohrane, koja se može koristiti za razmjenu podataka između zadataka:

struct MyCustomStruct { QByteArray data; };

Storage<MyCustomStruct> storage;

const auto onFirstSetup = [](NetworkQuery &task) { ... };
const auto onFirstDone = [storage](const NetworkQuery &task) {
    // storage-> gives a pointer to MyCustomStruct instance,
    // created dynamically by the running task tree.
    storage->data = task.reply()->readAll();
};
const auto onSecondSetup = [storage](ConcurrentCall<QImage> &task) {
    // storage-> gives a pointer to MyCustomStruct. Since the group is sequential,
    // the stored MyCustomStruct was already updated inside the onFirstDone handler.
    const QByteArray storedData = storage->data;
};

const Group group {
    // When the group is entered by a running task tree, it creates MyCustomStruct
    // instance dynamically. It is later accessible from all handlers via
    // the *storage or storage-> operators.
    sequential,
    storage,
    NetworkQueryTask(onFirstSetup, onFirstDone, CallDone::OnSuccess),
    ConcurrentCallTask<QImage>(onSecondSetup)
};

Dokumentacija funkcija članova

Group::Group(const Tasking::GroupItems &children)

Konstruira grupu s danim popisom children a.

Ovaj konstruktor je koristan kada dječji elementi grupe nisu poznati u vrijeme kompajliranja, već kasnije, u vrijeme izvođenja:

const QStringList sourceList = ...;

GroupItems groupItems { parallel };

for (const QString &source : sourceList) {
    const NetworkQueryTask task(...); // use source for setup handler
    groupItems << task;
}

const Group group(groupItems);

Group::Group(std::initializer_list<Tasking::GroupItem> children)

Konstruira grupu iz std::initializer_list danog pomoću children.

Ovaj konstruktor je koristan kada su svi podređeni elementi grupe poznati u vrijeme kompajliranja:

const Group group {
    finishAllAndSuccess,
    NetworkQueryTask(...),
    Group {
        NetworkQueryTask(...),
        Group {
            parallel,
            NetworkQueryTask(...),
            NetworkQueryTask(...),
        }
        ConcurrentCallTask<QString>(...)
    }
};

Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.