0
是否可以使用this.unblock()和percolate:synced-cron?我希望PJ2_1,PJ2_2,PJ2_3能夠快速打印出來,而不是等待Meteor.call()在10秒內完成,但事實並非如此。使用this.unblock()和Meteor percolate:synced-cron
實例工作:
SyncedCron.add({
name: 'pj2',
schedule: function(parser) {
return parser.text('every 30 seconds');
},
job: function() {
console.log("PJ2_1:");
Meteor.call('fa2', function(err, res) {
if (err) {
console.log("FA2: ERROR");
}
});
console.log("PJ2_2:");
Meteor.call('fa2', function(err, res) {
if (err) {
console.log("FA2: ERROR");
}
});
console.log("PJ2_3:");
}
});
例Meteor.methods():
if (Meteor.isServer) {
Meteor.methods({
'fa2': function() {
this.unblock();
const data = HTTP.get('http://www.fakeresponse.com/api/?data={%22Hello%22:%22World%22}&meta=false&sleep=10');
return data;
}
})
}
是否有理由在服務器上使用異步方法調用,而不是直接使用函數?你可以以更簡單的方式保持這種乾燥。 –
同意。直接使用HTTP.get與回調工作。 – cannin