Created
April 21, 2014 04:01
-
-
Save sdeering/11131879 to your computer and use it in GitHub Desktop.
node.js xhr with promises using q library
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
function _functionName(url) { | |
return Q.fcall(function () { | |
var deferred = Q.defer(); | |
var options = { | |
url: url, | |
headers: { | |
'User-Agent': 'my-app' | |
}, | |
json: true, | |
timeout: 60000 | |
}; | |
console.log( options.url ); | |
request.get( options, function ( err, res, body ) { | |
console.log(body); | |
deferred.resolve( body ); | |
}); | |
return deferred.promise; | |
}).then( function( results ) { | |
console.log('parse the results...'); | |
}).then( function ( results ) { | |
return Q.all( results ); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment