I'm a little unsure of how to ask this question, so I'll start as best I can from where I'm at. I have a data type, I'll call it "program", that I load some core information from a single data source. I have my loading / caching logic worked out for the central data model, but there are externally loaded nodes that my framework will need to append to the data model based on project settings.
What I'm looking for is a design pattern that will allow me to load these appended data nodes if the project requires it and to not execute the program until all the data has loaded. I can assume that I will know what the nodes will be in advance and where to get the data when they are required. My current setup looks something like below:
var programs = {},
loadCuePoints = function (uuid, callback) {
//will call the callback with the data once loaded and add the program
//to programs, keyed by the uuid
},
loadLinkedFiles = function (uuid, callback) {
//will append the data to programs[uuid] and call the callback with the
//data once loaded
},
loadProgram = function (uuid, callback) {
//will append the data to programs[uuid] and call the callback with the
//data once loaded
},
// hash where the key is the node on program and the value is the function
// used to load the data, this will be based on project settings, but I'm not
// concerned with this logic for this question
requiredData = {
cuePoints : loadCuePoints,
linkedFiles : loadLinkedFiles
},
getProgram = function(uuid, callback) {
if (programs[uuid]) {
callback(programs[uuid]);
} else {
//assume the key in the requiredData hash is the required node on
//Program, and that the value is the callback method, the functions
//in this table sre already set up to load the data and return it
//via the callback once loaded
}
}
I can certainly hack my way through this, so I'm not asking for a solution so much (unless you have something that works very well or is particularly elegant) as I'm asking if there's an established pattern for queuing a callback after a collection of asynchronous actions. I'm happy to elaborate if the explanation is unclear.