var RSVP = require('rsvp');
const callAsync = RSVP.denodeify(Meteor.call);
import unirest from 'unirest';
async function myfunction1() {
var promise = await new RVSP.Promise(function (resolve, reject) {
//business logic
var url = myURL;
var req = unirest("GET", url);
req.end(function (res) {
if (res.error) {
reject(res.statusCode);
} else {
resolve(res.body);
}
});
});
return promise;
}
async function testNonMeteorMethod() {
const res1 = await myfunction1();
const res2 = await myfunction2(res1); //Not shown by similar to myfunction1 for brevity
const res4 = await myfunction3(res2); // ditto
return res4;
}
Meteor.method({
async testMeteorMethod() {
const res1 = await myfunction1();
const res2 = await myfunction2(res1);
const res4 = await myfunction3(res2);
return res4;
}
});
Why
callASync('testMeteorMethod')
.then(txt => console.log('single txt is : ', txt))
.catch(reason => console.error('single reason is : ', reason));
results in:
single txt is : { _45: 0,
_81: 3,
_65: { _45: 0, _81: 0, _65: null, _54: null },
_54: null }
}
and
testNonMeteorMethod()
.then(txt => console.log('single txt is : ', txt))
.catch(reason => console.error('single reason is : ', reason));
results in the expected status code:
single txt is : 204
Or is it the case of parent testMeteorMethod, also need to embed child functions in Meteor.methods as well?