Skip to content

Instantly share code, notes, and snippets.

@domenic
Forked from benjamingr/gist:749bfe2b3c0411c7430c
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domenic/f19ba7fb48d53e2590fa to your computer and use it in GitHub Desktop.
Save domenic/f19ba7fb48d53e2590fa to your computer and use it in GitHub Desktop.
function ResourceBuilder(){
this._dependencyPromises = [];
}
ResourceBuilder.prototype._load = function () {
// specific to the resource...
};
ResourceBuilder.prototype.addDependency = function(dep){
this._dependencyPromises.add(dep);
}
ResourceBuilder.protototype.get = function(){
return Promise.all([this._load()].concat(this._dependencyPromises)).then(function(){
// both the resource and its dependencies are now loaded
// this was done in parallel.
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment