I have required npm future package in my meteor application
What can I do if the service providers server does not respond to a http call?
A. How long will future wait for the response.
B. (If it does wait forever) how can I stop the wait after 4 seconds and repeat the api call 3 more times before returning an error to the user?
Server.js
var requestFunction = function(callback) {
var f = new future()
request.post('http://ift.tt/1JCyuC3', {
oauth: {key: 'somekey'},
function ResponseFUnction(error, response, body) {
if (!err && response.statusCode === 200) {
var reqBody = querystring.parse(body)
var responseObj = {
oauth_token:reqBody.oauth_token,
authenticateUrl: 'http://ift.tt/17MTh41?' + qs.stringify({token: reqBody.oauth_token})
}
return f.return(responseObj)
}
else {
return f.return(error);
}
})
return f.wait()
};
var storeResponseObj = function(data) {
if (data === undefined) {
return 'no data was received'
}
else {
var store = Meteor.users.update(Meteor.user(), {$set: {'profile.responseFolder': data}})
return 'stored object successfully'
}
}
Meteor.methods({
ApiTokens: function() {
var functionOne = requestFunction()
var functionTwo = storeResponseObj(functionOne)
return functionOne
}
})
Aucun commentaire:
Enregistrer un commentaire