Closed brent-hoover closed 5 years ago
@zenweasel So, a few related points:
Hooks
and replace with appEvents
. This is one of the last breaking things we want to get merged prior to 2.0 final release.functionsByType
and explicitly call and await those in core plugins. Can you add a new function type for this, which other plugins can be aware of and register?functionsByType
in a certain order.)Point 3 is just an idealistic goal. If there isn't time to figure out how to do it all with events, then I'd go for functionsByType
solution.
@aldeed re point #3. That is what we were looking for but how does any particular event know it's the last one and doesn't that break encapsulation? I would also prefer an event-driven flow however it's t's the "somehow aware of which transforms we expect to run and whether they've all run" that made me fallback to using synchronous code.
Whether you are awaiting or responding to an event it seems like it's more of a semantic difference than an actual difference in how the tasks would be scheduled. Also, in this case we want the item to be published even if any of these transformations fail so it still seems like the caller needs to be responsible.
We need to be able to run all event handlers and then run a function afterwards.
So possibly a version that is
Hooks.Events.addAsync
and thenHooks.Events.runAsync
that runs all the handlers and then can run a function.Use Case: After I import a product, I want other modules to be able to run transformations on that imported product, but after they are all done, I want to publish the product.
We could just use
Promise.all
if we ensured that all functions added toHook.Events
returned a promise. Or we could use something likeasync.parallel
from theasync
library.