There are places in my application where an object should emit an event and should delay execution untill all event handlers have completed work. The event handlers might be performing an asynchronous operation (e.g. writing to database).
Application.on("login", function(evt) {
// Asynchronous operation (e.g. update info in database)
});
Application.trigger("login").then(function() {
// Execute stuff after all (async) event handlers are done
});
I've looked around and haven't found any established design patterns for this. I've got an implementation I'm happy with, but I'm curious if anyone has solved this differently?