如何讓客戶端的method.call等待異步函數完成?目前它到達函數的末尾並返回undefined。同步MeteorJS異步代碼Meteor.methods函數
Client.js
Meteor.call('openSession', sid, function(err, res) {
// Return undefined undefined
console.log(err, res);
});
Server.js
Meteor.methods({
openSession: function(session_id) {
util.post('OpenSession', {session: session_id, reset: false }, function(err, res){
// return value here with callback?
session_key = res;
});
}
});
我認爲不可能在客戶端的流星方法內執行異步任務。在使用光纖的服務器可能是一個選項。 – Andreas