how to determine which child was dispatched to by dispatchToChild
If you pass a list of children to dispatchToChild, or no children at all (meaning this.children), it will iterate through them and dispatch to the first started one. It is sometimes useful to know which was the last child dispatched to. How best to do this?
dispatchToChild currently returns Promise<boolean>, indicating that a dispatch happened. One possibility is to change this to a Promise<string | undefined>, where the result is the name of the child dispatched to or undefined if no dispatch happened.
#13 proposes making this return mean "dispatch happened and was successfully handled".
These don't necessarily have to conflict, but we should talk it out.
Another option is to simplify the signature of dispatchToChild by extracting out the "choose the best child" logic into a helper, e.g.
await this.dispatchToChild(this.getFirstStarted()); // choose first started from this.children, order unpredictable
// or
await this.dispatchToChild(this.getFirstStarted(FirstTopic, SecondTopic, ThirdTopic)); // choose first started by iterating through the named topics in order
Then if you need to know which was dispatched to you can do:
const child = this.getFirstStarted(FirstTopic, SecondTopic, ThirdTopic);
const wasHandled = await this.dispatchToChild(child);
The only reason I don't like this is that it's so nice just to call await this.dispatchToChild() as the default case.
It could be that this helper is called by dispatchToChild() but is extractable to make it explicit as shown above.