【发布时间】:2016-03-26 10:37:38
【问题描述】:
我正在尝试在我的 Meteor 应用程序中使用这个 NPM 包:Gumroad-API。当我尝试在 Promise 回调中执行 Meteor 方法调用(或集合插入)时,我在服务器端遇到了问题。
以下是我的两个 Meteor 方法的代码:
Meteor.methods({
testMethod: () => {
console.log('TEST METHOD RUN');
},
fetchGumroadData: () => {
const Gumroad = Meteor.npmRequire('gumroad-api');
let gumroad = new Gumroad({ token: Meteor.settings.gumroadAccessKey });
Meteor.call('testMethod'); // runs fine
gumroad.listSales('2014-12-04', '2099-12-04', 1).then((result) => {
console.log('1'); // runs fine
Meteor.call('testMethod'); // execution halts here w/o error msg
console.log('2'); // this never runs
});
},
});
每当我尝试在其中执行 Meteor.call() 时,.then() 回调中的代码总是停止(没有错误消息)。
当我将 Meteor.call() 替换为 Collection.insert() 时,我得到了相同的行为,例如:Sales.insert({text:'test'});。
【问题讨论】:
标签: javascript node.js meteor npm promise