Last active
August 29, 2015 14:07
-
-
Save justinbmeyer/86534ad9fbc560a89caf to your computer and use it in GitHub Desktop.
promise_queue.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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