Created
May 28, 2015 22:08
-
-
Save sillypog/8e3583f4679ecd9d50c9 to your computer and use it in GitHub Desktop.
Q Promises
This file contains hidden or 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
Q = require 'q' | |
init = () -> | |
console.log 'init' | |
promises = [checkS3FolderExists('MyData1'), checkS3FolderExists('MyData2')] | |
Q.all(promises).then (results)-> | |
console.log 'Done!' | |
console.log results | |
console.log 'init complete' | |
checkS3FolderExists = (folder) -> | |
console.log "checking for folder #{folder}" | |
params = | |
folder: folder | |
s3Request('listObjects', params) | |
s3Request = (task, params) -> | |
deferred = Q.defer() | |
setTimeout -> | |
deferred.resolve("Found folder: #{params.folder}") | |
, 1000 | |
deferred.promise | |
init() | |
### | |
Generated output: | |
init | |
checking for folder MyData1 | |
checking for folder MyData2 | |
init complete | |
Done! | |
[ 'Found folder: MyData1', 'Found folder: MyData2' ] | |
### | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment