【发布时间】:2016-01-15 05:58:48
【问题描述】:
我正在尝试验证 Meteor 中的允许挂钩。以下是我的工作。
let EasyPost = Npm.require('node-easypost')(process.env.EASYPOST_KEY);
Addresses.allow({
insert(userId, document) {
check(document, Addresses.simpleSchema());
EasyPost.createAndVerify(document, function (err, result) {
if (err) {
// insert should not be allowed.
} else {
document = Object.assign(document, {
easypost: result
})
}
})
}
});
但是,我不能使用return false,因为它是一个异步操作。有没有更好的方法来做到这一点?
【问题讨论】:
-
使用承诺?哪个函数是异步的?
标签: javascript asynchronous meteor easypost