I'm making a slew of modules, each of which will need to run code during various phases. I could use a Promise.all for each phase like:
const phase1promise = Promise.all([module1.phase1(),module2.phase1()]);
phase1promise.then(// do next phases)
Or, I could use an event emitter from a "master" module that submodules listen to in order to know when to run code for phases. In turn, the master module would listen to those submodules' event emitters to know when they're done for that phase. I rigged up this event emitter system and it's working but I'm starting to think that promises might be better, especially with respect to code running in parallel. Also, maybe promises could be considered a more standard pattern. Thoughts?
If it's just one "start" event and only one "end" event per module, and there's a master orchestrating all of this, then promises will be (by far!) simpler.
If the modules are supposed to register themselves with the master and/or emit multiple events for different parts, you will have greater flexibility (and a bit less coupling), but a much more complex system that's less clear to understand - needing to look at all files to figure out the dependency graph.