Skip to content

Instantly share code, notes, and snippets.

@justinbmeyer
Last active August 29, 2015 14:07
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 justinbmeyer/86534ad9fbc560a89caf to your computer and use it in GitHub Desktop.
Save justinbmeyer/86534ad9fbc560a89caf to your computer and use it in GitHub Desktop.
promise_queue.js
var promiseLock = (function(){
return function(func){
};
})();
///
var buildcache = {};
var build = function(docObject){
// does stuff preventing it from runing
return new Promise(function(resolve){
buildcache.building = docObject;
setTimeout(function(){
write(buildcache.building);
resolve();
}, Math.random() * 10000);
});
return promise;
};
var document = function(){
var filesPromise = getFiles();
var processPromise = filesPromise.then(function(files){
return process(files);
});
buildPromise = processPromise.then(function(docObject){
return promiseLock(function(){
return build(docObject);
});
});
};
Promise.all([
document("project1"),
document("project2")
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment