We want to be clear on how independent asynchronous activities are allowed to overlap and still provide reliable results when completed. Now in version 0.1.15.
We are motivated by more advanced network computing as suggested by Mechs at Sea.
We have assumed that blocks at the same indent run in sequence and leave useful results in the state that they share so long as they can complete promptly as they do in Testing Turtle Graphics Mech and Testing Linking in Mech.
We have also expected file and network results to be passed to their children, not their peers, as in Testing Sensor Mech and Testing File Mech.
.
We see that peer CLICKs and TICKs start together but finish independently with no cooperation.
CLICK TICK 4 HELLO TICK 4 HELLO HELLO world
If we want to overlap slow operations but somehow depend on their combined results, how do we do what we now think of as await Promise.all(...)
Consider SLEEP which has no output other than its effects on the sequencing of other blocks. Perhaps it is the first block to return a Promise when run.
CLICK HELLO SLEEP 1 HELLO SLEEP 3 HELLO
Maybe SLEEP could run its children, it's dreams, until it awakes and the run is canceled? Here we expect three smiles then one world.
CLICK SLEEP 3 TICK 10 HELLO HELLO world
.
State is passed forward among peers. A block that returns a promise is promising that its contribution to state will be complete when the promise resolves.
A shallow copy of state is passed to children. The parent can await this copy to be complete when all child promise resolve. Anticipated results from the copy can be moved into the parent's state as part of its own resolution.
It would be possible for a block to run all of its children independently each with their own shallow copy of state. This block would then copy some aggregation into its own state and resolve once Promise.all(children) of its children resolves. This block might be called TOGETHER.
CLICK TOGETHER SLEEP 3 SLEEP 5 SLEEP 1 SLEEP 2 HELLO world
Question: should a failed block resolve? Probably yes. Its failure to deliver anticipated results in state should be sufficient to prevent downstream damage from stumbling.
A TOGETHER type block, when applied to a list of files might collect an array of file contents from it's children:
[file,file,null,file]
Or, it might pass into each child an object to be completed:
[{name, file}, {name, file}, {name}, {name, file}]