I would like to start the root in main(). Then have the root class spawn a continuation called Stage1, then have stage1 allocate a continuation called Stage2, then have Stage 2 allocate a continuation of the root class?
Would this work? calling continuations in a loop? I would check in the root class whether I should continue or exit the loop.
What do you mean by "allocate a continuation of the root class?" A continuation task is scheduled to execute after the associated child tasks, either by previous planning (allocate continuation) or in the midst of task execution (recycle as continuation). In either case, the continuation task executes after all the children have completed and instead of the previous parent task. Root tasks have no parent and so can't replace a parent to execute after some children. However, you could have the Stage 2 task allocate yet another continuation task to execute after Stage 2's children, a "Stage 3" and continue that pattern of creating children and a new continuation task to execute when they finish. Is that the sort of idea you had in mind?