Here is an example of using RSVP
http://emberjs.com/api/classes/RSVP.Promise.html
var RSVP = require('rsvp');
const callAsync = RSVP.denodeify(Meteor.call);
function getJSON(url) {
return new Promise(function(resolve, reject){
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.onreadystatechange = handler;
xhr.responseType = 'json';
xhr.setRequestHeader('Accept', 'application/json');
xhr.send();
function handler() {
if (this.readyState === this.DONE) {
if (this.status === 200) {
resolve(this.response);
} else {
reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
}
}
};
});
}
getJSON('/posts.json').then(function(json) {
// on fulfillment
}, function(reason) {
// on rejection
});
But when I tried to put inside Meteor.methods
Meteor.methods({
async getJSON(url) {
});
and called it
callAsync('getJSON', url).then(function(json) {
// on fulfillment
console.log('JSON status code is : ', json);
}, function(reason) {
console.log('JSON error code code is : ', reason);
});
JSON status code is : { _45:0, _81:3, _65: _45: 0, _81: 0, _65: null, _54: null },
_54: null }
When I am expecting either 200 etc and able to pass back to calling function?