-
Task
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
None
-
None
The current "standard" TaskTree usage pattern (e.g. https://codereview.qt-project.org/c/qt-creator/qt-creator/+/671707) looks like
const auto onSetup = [input](Async<FormatOutput> &task) { task.setConcurrentCallData(format, input); }; const auto onDone = [editor = QPointer<PlainTextEdit>(editor), input](constAsync<FormatOutput> &task, DoneWithresult) { if (result == DoneWith::Cancel) showError(Tr::tr("Filewasmodified.")); else checkAndApplyTask(editor, input, task.result()); }; const auto onTreeSetup = [doc](TaskTree &taskTree) { QObject::connect(doc, &TextDocument::contentsChanged, &taskTree, &TaskTree::cancel); }; GlobalTaskTree::start({AsyncTask<FormatOutput>(onSetup, onDone)}, onTreeSetup);
which makes the onSetup/onDone lambdas and their actual use four lines below are "disconnected".
I wonder whether it would be possible to have a more "local" solution without losing the expressiveness of the 'onSetup' names, e.g something like
AsyncTask<FormatOutput> format { setup = [input](Async<FormatOutput> &task) { task.setConcurrentCallData(format, input); }, done = [editor = QPointer<PlainTextEdit>(editor), input](const Async<FormatOutput> &task, DoneWith result) { if (result == DoneWith::Cancel) showError(Tr::tr("File was modified.")); else checkAndApplyTask(editor, input, task.result()); } }; GlobalTaskTree::start( group = { format }, setup = [doc](TaskTree &taskTree) { QObject::connect(doc, &TextDocument::contentsChanged, &taskTree, &TaskTree::cancel); } );