【发布时间】:2017-06-07 06:29:25
【问题描述】:
我正在尝试在节点中使用 Promise。
但是,then 部分没有被执行。 第一个函数返回一个 resolve() 实例。 我该如何解决这个问题?
这是代码:
exports.refresh_access_token = function (environment_hash) {
...
Model.update(values, {where: where}).then(function () {
console.log('updated!');
resolve("Success!");
}).catch(function (err) {
console.log('error on update');
});
...
}
async.map(accounts, function (account) {
module.exports.refresh_access_token(account.environment_hash).then(function () {
console.log('async called back');
});
}
【问题讨论】:
-
The first function returns a resolve() instance什么是解析实例? -
这只是解决('成功');行
-
但是
resolve是什么?它没有特殊的内置含义,也没有在您的代码中定义 -
我只是在关注这个:davidwalsh.name/promises 它使用了 resolve('Success!');在其中一个例子中
-
Resolve 在该示例中是一个回调,它告诉承诺,好吧,解决。它不是全局变量。您的示例将引发异常。
标签: javascript node.js promise